Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
What command to check a scheduled timed shutdown/poweroff?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
BoGun
n00b
n00b


Joined: 16 Jul 2023
Posts: 12

PostPosted: Tue Oct 24, 2023 10:41 am    Post subject: What command to check a scheduled timed shutdown/poweroff? Reply with quote

Hi all,

Finally managed to figure out how to schedule a poweroff of my machine so that's great :-)

Using command = openrc-shutdown --poweroff [wanted time]

Problem is if I set a time/date many hours later I sometimes tend to forget about it :-/

So how can I check whether I've scheduled poweroff coming up?

I tried with some different commands that I found in different Linux forums but they all are either too old or refering to Debian based systems hence doesn't work.

Any ideas much welcomed.
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3139

PostPosted: Tue Oct 24, 2023 10:53 am    Post subject: Reply with quote

I don't know how exactly openrc-shutdown is different to regular shutdown command (which also schedules shutdown at specified time and is usable with openrc), but:
man shutdown wrote:

Usually shutdown displays warnings every 15 minutes and then every minute in the last 10 minutes of the countdown until time is reached. When
-q is specified shutdown only warns at 60 minute intervals, at the 10 minute mark, at the 5 minute mark, and when the shutdown process actually happens.


These warnings are broadcasted to all users on all terminals, and also should pop up when you login.
Back to top
View user's profile Send private message
BoGun
n00b
n00b


Joined: 16 Jul 2023
Posts: 12

PostPosted: Tue Oct 24, 2023 11:05 am    Post subject: Reply with quote

szatox wrote:
I don't know how exactly openrc-shutdown is different to regular shutdown command (which also schedules shutdown at specified time and is usable with openrc), but:
man shutdown wrote:

Usually shutdown displays warnings every 15 minutes and then every minute in the last 10 minutes of the countdown until time is reached. When
-q is specified shutdown only warns at 60 minute intervals, at the 10 minute mark, at the 5 minute mark, and when the shutdown process actually happens.


These warnings are broadcasted to all users on all terminals, and also should pop up when you login.


No sorry that doesn't happen on my machine. The "and also should pop up when you login" bit I ,mean.

Also FYI; have by "trial and error" come to the conclusion that only using "shutdown" doesn't work, hence "open-rc-shutdown".
Back to top
View user's profile Send private message
grknight
Retired Dev
Retired Dev


Joined: 20 Feb 2015
Posts: 1662

PostPosted: Tue Oct 24, 2023 12:40 pm    Post subject: Reply with quote

When using openrc-shutdown, it will create the file /run/openrc-shutdown.pid while running.
Since the "scheduled" shutdown doesn't actually exit the program, this file should still exist while a poweroff is pending.

However, there does not seem to be any indication of time remaining beyond any tty broadcasts every few minutes depending on how far out it was scheduled.

See the simple code for details.
Back to top
View user's profile Send private message
Banana
Veteran
Veteran


Joined: 21 May 2004
Posts: 1392
Location: Germany

PostPosted: Tue Oct 24, 2023 1:09 pm    Post subject: Reply with quote

BoGun wrote:
Also FYI; have by "trial and error" come to the conclusion that only using "shutdown" doesn't work, hence "open-rc-shutdown".


Only shutdown does not power off the system https://linux.die.net/man/8/shutdown
Maybe this is your problem with the command.
_________________
My personal space
My delta-labs.org snippets do expire

PFL - Portage file list - find which package a file or command belongs to.
Back to top
View user's profile Send private message
BoGun
n00b
n00b


Joined: 16 Jul 2023
Posts: 12

PostPosted: Wed Oct 25, 2023 8:31 am    Post subject: Reply with quote

Banana wrote:
BoGun wrote:
Also FYI; have by "trial and error" come to the conclusion that only using "shutdown" doesn't work, hence "open-rc-shutdown".


Only shutdown does not power off the system https://linux.die.net/man/8/shutdown
Maybe this is your problem with the command.


No I got that, please see initial post ;-) ...I'm using " openrc-shutdown --poweroff [wanted time] "
Back to top
View user's profile Send private message
BoGun
n00b
n00b


Joined: 16 Jul 2023
Posts: 12

PostPosted: Wed Oct 25, 2023 8:47 am    Post subject: Reply with quote

grknight wrote:
When using openrc-shutdown, it will create the file /run/openrc-shutdown.pid while running.
Since the "scheduled" shutdown doesn't actually exit the program, this file should still exist while a poweroff is pending.

However, there does not seem to be any indication of time remaining beyond any tty broadcasts every few minutes depending on how far out it was scheduled.

See the simple code for details.


Thanks for your time answering :-)

Sadly I'm a very "novice" user and reading "code" is a bit beyond my knowledge at the moment (learning all the time) but I think/hope I got you right?

So you're saying that I can sort of check if there is a pending shutdown/poweroff IF there is a file = openrc-shutdown.pid in the /run/ directory, is that correct?

And further you're saying there actually is no way of checking what scheduled time is set when it's beyond a certain time?

I've also noticed when experimenting that when I set a time just a few miniutes forward I immediately get a "confirmation message" in the CLI but this doesn't happen when I set many hours forward. That's a bit odd one would think?

Edit;FYI: noticed some more odd things; seemingly when seting a time many hours forward and as mentioned earlier not recieving a "confimation message" it seems that it's not possible to cancel with " openrc-shutdown -c " while when setting time just a few minutes forward and hence recieving the confirmationg it's suddenly possible cancel with the same command ... :? well as said, beyond my knowledge.
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3139

PostPosted: Wed Oct 25, 2023 9:27 am    Post subject: Reply with quote

You are the odd one :lol: This behavior you observe in shutdown may be inconsistent (which I agree usually is a bad thing), but it does actually make sense considering what it's used for.
A scheduled shutdown is something you do on servers and mainframes to let the users finish their running tasks or save progress on whatever they're working on. It can prevent new users from logging in too. It's actually quite common for servers to disable ssh login for non-root users after shutdown has been scheduled.
There is no need to "notify users in advance" on your own PC; you already know you're shutting it down, and init will notify the processes and wait for them to terminate before pulling the plug.

Which brings up a question: Why do you want to schedule shutdown many hours ahead in the first place? Just "shutdown -h now" when you're ready for the result to take place.
If you're doing something really fancy, perhaps scheduling with crontab (for recurring jobs) or at (for one-shots) would be a better option?
Back to top
View user's profile Send private message
grknight
Retired Dev
Retired Dev


Joined: 20 Feb 2015
Posts: 1662

PostPosted: Wed Oct 25, 2023 1:05 pm    Post subject: Reply with quote

BoGun wrote:
And further you're saying there actually is no way of checking what scheduled time is set when it's beyond a certain time?

I've also noticed when experimenting that when I set a time just a few miniutes forward I immediately get a "confirmation message" in the CLI but this doesn't happen when I set many hours forward. That's a bit odd one would think?

Edit;FYI: noticed some more odd things; seemingly when seting a time many hours forward and as mentioned earlier not recieving a "confimation message" it seems that it's not possible to cancel with " openrc-shutdown -c " while when setting time just a few minutes forward and hence recieving the confirmationg it's suddenly possible cancel with the same command ... :? well as said, beyond my knowledge.

The code says it sends a TTY broadcast according to the following schedule:
  • If greater than 180 minutes, send 60 minutes apart until under 180 minutes remain
  • Then, if greater than 60 minutes, send 30 minutes apart until under 60 minutes remain
  • Then, if greater than 10 minutes, send 15 minutes apart until under 10 minutes remain
  • Finally, send once a minute
This all assumes that openrc-shutdown is running the entire time. It won't exit on its own and the terminal/tty that starts it must remain.


Last edited by grknight on Wed Oct 25, 2023 7:26 pm; edited 1 time in total
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3345
Location: Rasi, Finland

PostPosted: Wed Oct 25, 2023 6:17 pm    Post subject: Reply with quote

szatox wrote:
I don't know how exactly openrc-shutdown is different to regular shutdown command
If you have USE="sysv-utils" for openrc, then you'll get this:
contents of /sbin/shutdown:
#!/bin/sh

do_halt=false
while getopts :akrhPHfFnct: opt; do
        case "$opt" in
                a) ;;
                k) ;;
                r)
                        shutdown_arg=--reboot
                        ;;
                h)
                        do_halt=true
                        shutdown_arg=--poweroff
                        ;;
                P)
                        if ! ${do_halt}; then
                                printf "%s\n" "The -P flag requires the -h flag" >&2
                                exit 1
                        fi
                        shutdown_arg=--poweroff
                        ;;
                H)
                        if ! ${do_halt}; then
                                printf "%s\n" "The -H flag requires the -h flag" >&2
                                exit 1
                        fi
                        shutdown_arg=--halt
                        ;;
                f) ;;
                F) ;;
                n) ;;
                c) ;;
                t) ;;
                [?]) printf "%s\n" "${0##*/}: invalid command line option" >&2
                exit 1
                ;;
        esac
done
shift $((OPTIND-1))

if [ -z "${shutdown_arg}" ]; then
        shutdown_arg=--single
fi

printf "%s %s\n" "/sbin/openrc-shutdown ${shutdown_arg}" "$@"
exec /sbin/openrc-shutdown ${shutdown_arg} "$@"
So it's basically the same, but mostly used in setups where init=/sbin/openrc-init.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3139

PostPosted: Wed Oct 25, 2023 8:36 pm    Post subject: Reply with quote

I still use openrc with sysvinit and both shutdowns are ELF binaries on my system (and they are different sizes). Huh... Learn something every day.
Probably doesn't really matter anyway though :lol:
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3345
Location: Rasi, Finland

PostPosted: Wed Oct 25, 2023 9:11 pm    Post subject: Reply with quote

szatox wrote:
Probably doesn't really matter anyway though :lol:
There's the point right there. ;)
Like with many things in life (Gentoo), use what fits best for you. ;)
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
sabayonino
Veteran
Veteran


Joined: 03 Jan 2012
Posts: 1015

PostPosted: Wed Oct 25, 2023 10:25 pm    Post subject: Reply with quote

A simple root cronjob istance :

Edit root cronjob
Code:
# crontab -e



Edit and Test the shutdown command (-k option) to shutdown your system every day at 22.30
Code:
30 22 * * * shutdown -k -t 300 -h now  "Gentoo will be power off ...save your work !!"


To test the shutdown istance , run this every minutes
Code:
* * * * * blah blah


If it forks , remove the "-k" option to the root cronjob command line and set your time to shutdown
Code:
crontab -e


-k --> fake shutdown (remove this flag if your script works )
-t 300 ---> delay in seconds (300 secs = 5 minutes) between the warning message and the shutdown action

see
Code:
shutdown --help


The warning message will be send to all users/tty or local message broadcasting if available

cheers


[hr]
Quote:

Broadcast message from root@gentoo-18 (Thu Oct 26 00:28:01 2023):

Gentoo will be power off...save your work !!
The system is going down for system halt NOW!

_________________
LRS i586 on G.Drive
LRS x86-64 EFI on MEGA
Back to top
View user's profile Send private message
grknight
Retired Dev
Retired Dev


Joined: 20 Feb 2015
Posts: 1662

PostPosted: Wed Oct 25, 2023 11:59 pm    Post subject: Reply with quote

sabayonino wrote:
Edit and Test the shutdown command (-k option) to shutdown your system every day at 22.30
Code:
30 22 * * * shutdown -k -t 300 -h now  "Gentoo will be power off ...save your work !!"

Except this will shutdown immediately with openrc-shutdown. -t and -k are ignored. Not to mention the quoted text may throw an error.
Back to top
View user's profile Send private message
BoGun
n00b
n00b


Joined: 16 Jul 2023
Posts: 12

PostPosted: Thu Oct 26, 2023 8:41 am    Post subject: Reply with quote

:o :lol: :lol: :)

OMG my "little question" has gone way beyond my tiny little knowledge.

i'm feeling humlbed of you clever guys knowledge.

@ grknight; re. yours "It won't exit on its own and the terminal/tty that starts it must remain."

I'm not 100% sure I understand you right but if you mean that one needs to have the terminal window open on the machine from where I send the command to actually get it to work on the remote machine it seemingly works anyway, e.g if I send the command to remote machine and close down terminal on my sending machine the remote will shutdown. I just tested it. Allthough only with a shutdown just a few minutes forward.

@ szatox; "Huh... Learn something every day. " ...so true! :)

Also sorry if my english isn't 100%, it's not my native language.
Back to top
View user's profile Send private message
sabayonino
Veteran
Veteran


Joined: 03 Jan 2012
Posts: 1015

PostPosted: Thu Oct 26, 2023 10:52 am    Post subject: Reply with quote

grknight wrote:
sabayonino wrote:
Edit and Test the shutdown command (-k option) to shutdown your system every day at 22.30
Code:
30 22 * * * shutdown -k -t 300 -h now  "Gentoo will be power off ...save your work !!"

Except this will shutdown immediately with openrc-shutdown. -t and -k are ignored. Not to mention the quoted text may throw an error.


I don't know about openrc-shutdown comnd but what I posted works locally (and on eemote machine ).

I don't know how to monitor the remote process through remote machine (telnet ? ssh ? ...)

reading the previous post of BoGun I suppose he want to monitoring the remote shutdown process :roll:
_________________
LRS i586 on G.Drive
LRS x86-64 EFI on MEGA
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3345
Location: Rasi, Finland

PostPosted: Thu Oct 26, 2023 11:16 am    Post subject: Reply with quote

sabayonino wrote:
I don't know about openrc-shutdown comnd
openrc-shutdown --help:
Usage: openrc-shutdown -c | --cancel
   or: openrc-shutdown -R | --reexec
   or: openrc-shutdown -w | --write-only
   or: openrc-shutdown -H | --halt time
   or: openrc-shutdown -K | --kexec time
   or: openrc-shutdown -p | --poweroff time
   or: openrc-shutdown -r | --reboot time
   or: openrc-shutdown -s | --single time

Options: [ cdDfFHKpRrswChqVv ]
  -c, --cancel                      cancel a pending shutdown
  -d, --no-write                    do not write wtmp record
  -D, --dry-run                     print actions instead of executing them
  -H, --halt                        halt the system
  -K, --kexec                       reboot the system using kexec
  -p, --poweroff                    power off the system
  -R, --reexec                      re-execute init (use after upgrading)
  -r, --reboot                      reboot the system
  -s, --single                      single user mode
  -w, --write-only                  write wtmp boot record and exit
  -h, --help                        Display this help output
  -C, --nocolor                     Disable color output
  -V, --version                     Display software version
  -v, --verbose                     Run verbosely
  -q, --quiet                       Run quietly (repeat to suppress errors)

_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
sabayonino
Veteran
Veteran


Joined: 03 Jan 2012
Posts: 1015

PostPosted: Thu Oct 26, 2023 11:30 am    Post subject: Reply with quote

Zucca wrote:
sabayonino wrote:
I don't know about openrc-shutdown comnd
openrc-shutdown --help:
Usage: openrc-shutdown -c | --cancel
   or: openrc-shutdown -R | --reexec
   or: openrc-shutdown -w | --write-only
   or: openrc-shutdown -H | --halt time
   or: openrc-shutdown -K | --kexec time
   or: openrc-shutdown -p | --poweroff time
   or: openrc-shutdown -r | --reboot time
   or: openrc-shutdown -s | --single time

Options: [ cdDfFHKpRrswChqVv ]
  -c, --cancel                      cancel a pending shutdown
  -d, --no-write                    do not write wtmp record
  -D, --dry-run                     print actions instead of executing them
  -H, --halt                        halt the system
  -K, --kexec                       reboot the system using kexec
  -p, --poweroff                    power off the system
  -R, --reexec                      re-execute init (use after upgrading)
  -r, --reboot                      reboot the system
  -s, --single                      single user mode
  -w, --write-only                  write wtmp boot record and exit
  -h, --help                        Display this help output
  -C, --nocolor                     Disable color output
  -V, --version                     Display software version
  -v, --verbose                     Run verbosely
  -q, --quiet                       Run quietly (repeat to suppress errors)


I know the help of the command but I have never had the opportunity to use openrc-* :wink:
_________________
LRS i586 on G.Drive
LRS x86-64 EFI on MEGA
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3345
Location: Rasi, Finland

PostPosted: Thu Oct 26, 2023 12:54 pm    Post subject: Reply with quote

sabayonino wrote:
I know the help of the command but I have never had the opportunity to use openrc-* :wink:
I meant to give you the list of arguments which openrc-shutdown accepts. :wink:
Since openrc-shutdown doesn't support -k, then maybe wall (for example) sholud be used first, then wait and finally run the actual shutdown.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
BoGun
n00b
n00b


Joined: 16 Jul 2023
Posts: 12

PostPosted: Fri Oct 27, 2023 9:40 am    Post subject: Reply with quote

BoGun wrote:
e.g if I send the command to remote machine and close down terminal on my sending machine the remote will shutdown. I just tested it. Allthough only with a shutdown just a few minutes forward


Sorry I made a mistake so have to correct my "e.g if I send the command to remote machine and close down terminal on my sending machine the remote will shutdown. I just tested it. Allthough only with a shutdown just a few minutes forward." this is not true! It actually works as "grknight" explained, e.g if terminal is shutdown on sending machine after giving the command absolutely nothing happens on the remote. E.g it does not power off at set time.

Which rises a new question for me, is there any way to set a power off timer and being able to shut down the sending terminal? Real reason I want to shut down terminal has actually more to do with that I want to power off the sending machine after giving the command. But from reading what "grkninght" explains about the openrc-shutdown command I guess not possible?
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3139

PostPosted: Fri Oct 27, 2023 11:55 am    Post subject: Reply with quote

BoGun, check out "screen", it's very convenient when working on remote machines, since it maintains your session (so you don't get logged out and programs keep running) when your connection breaks, and you can later re-attach your virtual terminal and continue.
Other options are:
nohup command &
command & disown $! (AFAIR this one requires you to redirect input and outputs yourself; nohup does it automagically)

I have seen shutdown release terminal immediately too, though I think it was on binary distros using systemd. I don't know whether it was a config option or implementation detail.
Back to top
View user's profile Send private message
BoGun
n00b
n00b


Joined: 16 Jul 2023
Posts: 12

PostPosted: Sat Oct 28, 2023 3:34 pm    Post subject: Reply with quote

szatox wrote:
BoGun, check out "screen", it's very convenient when working on remote machines, since it maintains your session (so you don't get logged out and programs keep running) when your connection breaks, and you can later re-attach your virtual terminal and continue.
Other options are:
nohup command &
command & disown $! (AFAIR this one requires you to redirect input and outputs yourself; nohup does it automagically)

I have seen shutdown release terminal immediately too, though I think it was on binary distros using systemd. I don't know whether it was a config option or implementation detail.


Many thanx szatox, looked into your suggestions but I'm afraid it's beyond my knowledge. But when / if time permits I will try / look harder.

Cherrs.
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3139

PostPosted: Sat Oct 28, 2023 5:56 pm    Post subject: Reply with quote

I'll give you a hint for screen:

This is how you start:
screen -DR

This is how you take a break:
Ctrl+A followed by D

This is how you switch to scrollback:
Ctrl+A followed by [

It allows much more, but those 3 things above are all you need for the most basic functionality. Have fun!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum