The script below restarts a virtual machine instance on boot as per the instructions on the virtual machines page. It assumes the following:
nano
./srv/nano/
subdirectory.
This file has to be placed in the /etc/init.d/
subdirectory and activated with:
chmod +x /usr/sbin/nano /usr/sbin/update-rc.d nano defaults
after which the virtual machine can be booted using:
/etc/init.d/nano restart
#!/bin/sh ########################################################################### ## Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3 ## ## Please see: http://www.gnu.org/licenses/gpl.html for legal details, ## ## rights of fair usage, the disclaimer and warranty conditions. ## ########################################################################### ### BEGIN INIT INFO # Provides: nano # Required-Start: $local_fs $remote_fs $network $syslog $named # Required-Stop: $local_fs $remote_fs $network $syslog $named # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # X-Interactive: false # Short-Description: nano service ### END INIT INFO #nano service NANO_USER="nano" start() { echo "Starting nano..." HOMEDIR=`getent passwd $NANO_USER | cut -d: -f6` if [ -f $HOMEDIR/nano.img ]; then HOME="$HOMEDIR" start-stop-daemon --start -c root --pidfile $HOMEDIR/nano.pid --make-pidfile --exec /usr/bin/kvm -- -hda $HOMEDIR/nano.img -m 512 -cpu kvm64 -name nano -enable-kvm -net nic,vlan=0 -net tap,vlan=0,ifname=nan0,script=$HOMEDIR/nan-up.sh -pidfile $HOMEDIR/nano.pid -runas nano -daemonize -vnc :1 fi } stop() { echo "Stopping nano..." HOMEDIR=`getent passwd $NANO_USER | cut -d: -f6` if [ -f $HOMEDIR/nano.img ]; then start-stop-daemon -o -c $NANO_USER -K -u $NANO_USER --pidfile $HOMEDIR/nano.pid -x /usr/bin/kvm -- -hda $HOMEDIR/nano.img -m 512 -cpu kvm64 -name nano -enable-kvm -net nic,vlan=0 -net tap,vlan=0,ifname=nan0,script=$HOMEDIR/nan-up.sh -pidfile $HOMEDIR/nano.pid -runas nano -daemonize -vnc :1 fi } status() { dbpid=`pgrep -u $NANO_USER kvm` if [ -z $dbpid ] ; then echo "kvm for USER $NANO_USER: not running." else echo "kvm for USER $NANO_USER: running (pid $dbpid)" fi } case "$1" in start) start ;; stop) stop ;; restart|reload|force-reload) stop start ;; status) status ;; *) echo "Usage: /etc/init.d/nano {start|stop|reload|force-reload|restart|status}" exit 1 esac exit 0