VirtualBox VBoxManage for autostart

I have a script tact:/etc/vbox/register-autostart.sh which will register a VirtualBox VM for auto-start. It required other config in /etc/vbox the details of which I don’t remember, but I think it’s done now anyway… there’s more information in Starting virtual machines during system boot.

  online "$machine" && {

    report "halting machine '$machine'...";

    ssh "$machine" sudo poweroff;

    report "waiting a moment...";

    sleep 8;

  };

  run VBoxManage modifyvm "$machine" --autostart-enabled on;

  run sudo service vboxautostart-service restart;

Registering a systemd Service

So today I read How To Set Up VNC Server on Debian 8 which had a section on creating and registering the requisite scripts:

/usr/local/bin/myvncserver (make sure it’s executable with +x):

#!/bin/bash
PATH="$PATH:/usr/bin/"
DISPLAY="1"
DEPTH="16"
GEOMETRY="1024x768"
OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
case "$1" in
start)
/usr/bin/vncserver ${OPTIONS}
;;
stop)
/usr/bin/vncserver -kill :${DISPLAY}
;;
restart)
$0 stop
$0 start
;;
esac
exit 0

/lib/systemd/system/myvncserver.service:

[Unit]
Description=VNC Server example

[Service]
Type=forking
ExecStart=/usr/local/bin/myvncserver start
ExecStop=/usr/local/bin/myvncserver stop
ExecReload=/usr/local/bin/myvncserver restart
User=vnc

[Install]
WantedBy=multi-user.target

Then to register and start:

systemctl daemon-reload
systemctl enable myvncserver.service
systemctl start myvncserver.service