#!/bin/bash
#
# autoreg           Automatic registration of VirtualBox VMs
#
# chkconfig: - 30 60
# description: http://sunweb.elcom.spb.ru:8888/group/elcom/wiki/-/wiki/Main/TDCAutoRegVM
### BEGIN INIT INFO
# Provides: nfs
# Required-Start: $local_fs $network $syslog
# Required-Stop: $local_fs $network $syslog
# Default-Stop: 0 1 6
# Short-Description: Automatic registration of VirtualBox VMs
# Description: http://sunweb.elcom.spb.ru:8888/group/elcom/wiki/-/wiki/Main/TDCAutoRegVM
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

export PYTHONPATH='/opt/autoreg/'
RETVAL=0

uid=`id | cut -d\( -f1 | cut -d= -f2`

case $1 in
    start)
        # Only root can start the service
        [ $uid -ne 0 ] && exit 4
        
        echo -n $"Starting autoreg: "
        daemon $PYTHONPATH/run-autoreg.py
        RETVAL=$?
        echo
    ;;
    stop)
        echo -n $"Stopping autoreg: "
        killproc $PYTHONPATH/run-autoreg.py
        RETVAL=$?
        echo
    ;;
    status)
        status -l autoreg run-autoreg.py
    ;;
    restart)
        $0 stop
        $0 start
    ;;
esac

exit $RETVAL


