About

The script below restarts a virtual machine instance on boot as per the instructions on the virtual machines page. It assumes the following:

  • the virtual machine will be running under user nano.
  • the virtual machine is located under the /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

Code

This script was used on Debian Squeeze 6.0.6!

nano
#!/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

unix/systemv/init_scripts/nano.txt ยท Last modified: 2022/04/19 08:28 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.