Ask Your Question
1

make systemd shutdown wait

asked 2016-05-29 10:30:51 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I have this issue for virtualbox specifically but it also applies to any process that takes a while to shut down; the command

systemctl --user stop ...

returns before the VM has shut down, and the command

systemctl reboot

powers the system off before the VM has shut down

Is there any way to got systemd to wait for virtualbox? I tried the TimeoutStopSec=99 below for this but it's not working.

I'm not averse to having an arbitrary wait in there (so even if the VM is stopped, systemd still waits 30 more seconds for virtualbox

here's my user service file

Description=VBox Virtual Machine  Service

[Service]

ExecStart=-/bin/VirtualBox --comment 20150414 --startvm  20150831_64b01 --no-startvm-errormsgbox -seamless  

TimeoutStopSec=99
#ExecStop=/bin/vboxmanage controlvm 20150831_64b01 acpipowerbutton
#ExecStop=/bin/vboxmanage controlvm 20150831_64b01 savestate
#ExecStop=-/bin/vboxmanage guestcontrol 20150831_64b01 execute --image "%SystemRoot%\system32\shutdown.exe" --username sm  --password pass --wait-exit -- "-s" "-f" "-t" "0" 
ExecStop=/bin/vboxmanage guestcontrol 20150831_64b01 execute --image '%SystemRoot%/system32/shutdown.exe' --username sm  --password pass --wait-exit -- -f -s -t 0 
#ExecStop=-/bin/vboxmanage guestcontrol 20150831_64b02 execute --image '%SystemRoot%/system32/shutdown.exe' --username sm  --password pass --wait-exit -- -s -t 0 

#NEED 4 ExecStop ?
RemainAfterExit=true
KillMode=none

[Install]
WantedBy=multi-user.target

#https://technet.microsoft.com/en-ca/library/bb491003.aspx
#Syntax
#shutdown [{-l|-s|-r|-a}] [-f] [-m [\\ComputerName]] [-t xx] [-c "message"] [-d[u][p]:xx:yy]
#Top of page 
#Parameters
#-l   : Logs off the current user, this is also the defualt. -m ComputerName takes precedence.
#-s : Shuts down the local computer.
#-r   : Reboots after shutdown.
#-a   : Aborts shutdown. Ignores other parameters, except -l and ComputerName. You can only use -a during the time-out period.
#-f   : Forces running applications to close.
#-m [ \\ ComputerName ] : Specifies the computer that you want to shut down.
#-t   xx   : Sets the timer for system shutdown in xx seconds. The default is 20 seconds.
#-c   " message "   : Specifies a message to be displayed in the Message area of the System Shutdown window. You can use a maximum of 127 characters. You must enclose the message in quotation marks.
#-d [ u ][ p ] : xx : yy   : Lists the reason code for the shutdown. The following table lists the different values.
edit retag flag offensive close merge delete

Comments

There is a parameter there, -t that sets the timer for shutdown with a default of 20 seconds. Is there a reason you're not using it?

sideburns gravatar imagesideburns ( 2016-05-29 13:33:20 -0500 )edit

the -t is a grace period for windows users to shut down their work before the actual shutdown process kicks off - has no real effect for my purposes.

And I used 99 as a test earlier to confirm this.

sksharma gravatar imagesksharma ( 2016-05-30 10:58:51 -0500 )edit

Thank you. Asked and answered.

sideburns gravatar imagesideburns ( 2016-05-30 13:12:04 -0500 )edit

the -t is a grace period for windows ... has no real effect for my purposes.

to clarify further, the -t parameter is for the guest OS's shutdown command - it's passed to the windows command

"%SystemRoot%\system32\shutdown.exe"

& has nothing to do with systemd - systemd never sees it

sksharma gravatar imagesksharma ( 2016-05-30 22:35:38 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-06-21 14:28:13 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

use the multiple ExecStop feature - systemd runs them serially, should wait for the 2nd ExecStop to finish before the service is considered stopped & poweroff/shutdown proceeds

it's not ideal as it may wait longer than needed, or if one guesses a shorter-than-needed time, shutdown will still kill the service earlier than needed but it's better than before.

ExecStop=/bin/vboxmanage guestcontrol 20150831_64b01 execute --image '%SystemRoot%/system32/shutdown.exe' --username sm  --password PASS --wait-exit -- -f -s -t 0 
ExecStop=/usr/bin/sleep 25
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-05-29 10:30:51 -0500

Seen: 2,200 times

Last updated: Jun 21 '16