VirtualBox and systemd

- Start virtualbox vms on boot with systemd

[Unit] 
Description="Start %i"
After=syslog.target network.target
[Service]
Type=simple
User=fakini
ExecStart=/etc/init.d/vm_init.sh %i start
ExecStop=/etc/init.d/vm_init.sh %i stop
ExecReload=/etc/init.d/vm_init.sh %i restart
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
#!/bin/bash

vm=$1 
do=$2
function start_vm() {   if vboxmanage list runningvms | grep $vm    then        echo "$vm already up!"    else        vboxmanage startvm ${vm} --type headless && sleep 5    fi }
function stop_vm() {     if vboxmanage list runningvms | grep $vm     then       echo "Stopping ${vm}" && vboxmanage controlvm ${vm} poweroff     else       echo "$vm already down!"     fi }
function check_vm() {     if vboxmanage list runningvms | grep $vm   then         echo "$vm up!"   else       echo "$vm down!"   fi }
function restart_vm() {     if vboxmanage list runningvms | grep $vm     then         echo "$vm up! Reseting..." \         && vboxmanage controlvm ${vm} reset     else         echo "$vm down!"     fi }
case "$2" in     start)         start_vm || exit 1     ;;     stop)         stop_vm || exit 1     ;;     status)         check_vm     ;;     restart)         restart_vm     ;;     *)         echo "USAGE: $0 <vm> <stop|start>" esac