systemd to wait for command to complete before restart/shutdown or killing other processes
When I'm initiating "reboot" or "poweroff", systemd is killing all the processes, but I need it to wait for one particular application to finish before stopping other services.
Actually, I want Virtualbox vm clean shutdown/savestate. Have no problem of doing it manually with this service file, but during the shutdown - processes are killed. How can I control it?
I've read docs, but didn't find clear solution for this kind of dependency.
[Unit]
Description=virtualbox vm1 vm control service
After=vboxweb-service.service
Before=shutdown.target
[Service]
Type=oneshot
ExecStart=/usr/bin/VBoxManage startvm vm1 -type vrdp
ExecStop=/usr/bin/VBoxManage controlvm vm1 savestate
RemainAfterExit=true
Solved.
[Unit]
Description=virtualbox windows vm control service
After=vboxweb-service.service
Before=shutdown.target reboot.target halt.target
[Service]
Type=oneshot
ExecStart=/usr/bin/VBoxManage startvm windows -type vrdp
ExecStop=/usr/bin/VBoxManage controlvm windows savestate
RemainAfterExit=true
KillMode=none
[Install]
WantedBy=multi-user.target