You are not logged in.
Hi, very happy with a systemd service that starts and stops (savestate) one/some VirtualBox vm's at logon/startup. But now, after playing around with a little change and reverting back to the always working script, somehow the ExecStop doesn't trigger anymore. In other words: my vm's get started at logon but when I shutdown they aren't nicely savedstated anymore (but aborted). The service seems to be running fine. Can't figure out what happened/changed? Perfomed all kinds of sudo systemctl daemon-reloads, re-enabling of the service files, ...??? Any help much appreciated, Zach!
The (for months working) contents of the service file in /etc/systemd/system/:
[Unit]
Description=VM autostart WinarchFamily
After=network.target vboxdrv.service
Before=runlevel2.target shutdown.target
[Service]
User=zach
Group=vboxusers
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
#KillMode=process
KillMode=control-group
GuessMainPID=no
RemainAfterExit=yes
ExecStart=/usr/bin/VBoxManage startvm WinarchFamily --type headless
ExecStop=/usr/bin/VBoxManage controlvm WinarchFamily savestate
ExecStop=/usr/bin/VBoxManage controlvm Winarch savestate
[Install]
WantedBy=multi-user.target
Offline
Please edit your first post and use code tags for the unit file.
That is not the documented way to run a VM with a service as described in the Wiki. The Wiki method ensures that each VM is a separate service instance managed by systemd. You are managing two different VMs in a single service and there's also no corresponding ExecStart for the 'Winarch' guest. Try using the documented method first.
Offline
Hi twelveeighty,
Tried your advice, it works again for my "first" vm. What worked in the passed (not compliant to the Wiki advice I have to admit) was that when I also manually started the vm Winarch, it (when i forgot) nicely savestated that vm too (and later also others). Now I'm gonna create a separate service/unit file for every vm and follow the scripting advice of the Wiki. Thx! Regards, Zach
Offline
Hi, I've created a separate service/unit systemd file for all four vm's I frequently use. Still, now, only my first vm gets savedstate cleanly. The others are aborted (or powered off). Do I need to use TimeoutSec as an option or anything else in the additional service/unit files for them to close these vm's cleanly too? Thx again, regards, Zach
[Unit]
Description=WinarchFamily autostart and autosavestate
Requires=systemd-modules-load.service
After=systemd-modules-load.service
[Service]
User=zach
Group=vboxusers
ExecStart=/usr/bin/VBoxManage startvm WinarchFamily --type headless
ExecStop=/usr/bin/VBoxManage controlvm WinarchFamily savestate
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Offline
Hi, got it working again by adding KillMode=none and TimeoutStopSec=40 (as stated in the wiki :-), sorry). Now when I check the status of one of the services I get a warning about KillMode=none (being deprecated) and that I should switch to a more safe KillMode. Any advice on this? How does this work? Regards, Zach
Offline
KillMode=
Specifies how processes of this unit shall be killed. One of control-group, mixed, process, none.If set to control-group, all remaining processes in the control group of this unit will be killed on unit stop (for services: after the stop
command is executed, as configured with ExecStop=). If set to mixed, the SIGTERM signal (see below) is sent to the main process while the
subsequent SIGKILL signal (see below) is sent to all remaining processes of the unit's control group. If set to process, only the main
process itself is killed (not recommended!). If set to none, no process is killed (strongly recommended against!). In this case, only the
stop command will be executed on unit stop, but no process will be killed otherwise. Processes remaining alive after stop are left in their
control group and the control group continues to exist after stop unless empty.Note that it is not recommended to set KillMode= to process or even none, as this allows processes to escape the service manager's lifecycle
and resource management, and to remain running even while their service is considered stopped and is assumed to not consume any resources.Processes will first be terminated via SIGTERM (unless the signal to send is changed via KillSignal= or RestartKillSignal=). Optionally, this
is immediately followed by a SIGHUP (if enabled with SendSIGHUP=). If processes still remain after the main process of a unit has exited or
the delay configured via the TimeoutStopSec= has passed, the termination request is repeated with the SIGKILL signal or the signal specified
via FinalKillSignal= (unless this is disabled via the SendSIGKILL= option). See kill(2) for more information.Defaults to control-group.
Online
... that I should switch to a more safe KillMode.
First, time how long it takes to gracefully shut down the VM and save its state. That can take a while, especially if you have more than one VM being shut down and all have their states saved simultaneously. So also make sure you time it when shutting down all VMs at the same time and wait for all of them to gracefully stop. I'd say to be safe, double that and use that as the TimeoutStopSec= parameter. Then use the default 'control-group' for KillMode. If you configured it properly, the timeout would never be reached and if there's something hung on the VM, you would want systemd to clean up.
I would also not recommend using TimeoutSec, but both TimeoutStopSec and TimeoutStartSec individually since startup and shutdown could have very different durations, but that's just personal preference.
Offline
Hi, aha great info! Thx. I'm also diving in man systemd.service now...interesting. Regards, Zach
Offline
Hi, still struggling to get the second vm also nicely savedstated at shutdown. When I do a status check on the services I find that both vm's become part of one control group. As if both services are combined in one? Maybe this can explain why I can't get the second vm to close via the ExecStop (savestate)? Regards, Zach
CGroup: /system.slice/WinarchFamily_vm_autostart_savestate.service
├─876 /usr/lib/virtualbox/VBoxXPCOMIPCD
├─891 /usr/lib/virtualbox/VBoxSVC --auto-shutdown
├─915 /usr/lib/virtualbox/VBoxHeadless --comment WinarchFamily --startvm f0293c9f-087b-4dd>
└─916 /usr/lib/virtualbox/VBoxHeadless --comment Winarch --startvm 3a80bb2c-35be-41b6-a548>
Offline
Please post your full current service file in [ code ] tags.
Offline
Hi, i have created 2 separate service files and enabled them both. One for vm WinarchFamily and one for vm Winarch. Only the first is correctly savedstated via the ExecStop command. Both start correct all the time. Also read this thread (dated), seems to hint in the direction I thought too: https://bbs.archlinux.org/viewtopic.php?id=162671...
[Unit]
Description=Winarch autostart and autosavestate
Requires=systemd-modules-load.service
After=systemd-modules-load.service
[Service]
User=zach
Group=vboxusers
TimeoutStopSec=60
RemainAfterExit=yes
ExecStart=/usr/bin/VBoxManage startvm Winarch --type headless
ExecStop=/usr/bin/VBoxManage controlvm Winarch savestate
[Install]
WantedBy=multi-user.targetRegards, Zach
Last edited by zachalexy (2020-12-31 15:36:36)
Offline
Hi, if I exactly follow the Wiki with the not adviced KillMode=none, it works... Both vm's are being savedstated at shutdown and brought up again when I start/logon. Gonna test this for a few days...
[Unit]
Description=Winarch autostart and autosavestate
Requires=systemd-modules-load.service
After=systemd-modules-load.service
[Service]
User=zach
Group=vboxusers
ExecStart=/usr/bin/VBoxManage startvm Winarch --type headless
ExecStop=/usr/bin/VBoxManage controlvm Winarch savestate
RemainAfterExit=yes
KillMode=none
TimeoutStopSec=60
[Install]
WantedBy=multi-user.targetOffline
Hi, rebooted several times, perfect. Seems like KillMode=none is the magic parameter!? Joohoo... regards, Zach
Offline
Hi, in terms of savestating running VM's without manual interaction at Shutdown...fine. Get a message at shutdown that /tmp can't be unmounted. No big issue I guess, has to do with the KillMode probably. Any tips on a different solution to savestate two or more VM's at shutdown more than welcome. Regards, Zach
Offline