5

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
GioMac
  • 4,544
  • 4
  • 27
  • 41

1 Answers1

4

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
GioMac
  • 4,544
  • 4
  • 27
  • 41
  • 1
    According to the man page, the `Before` is actually problematic. The `Before` relation is evaluated in reverse order when the services are stopped, meaning that all of shutdown, reboot and halt will be executed /before/ your service will be stopped. – fotNelton Aug 26 '14 at 12:06