init-functions 1.74 KB
Newer Older
Sigmund Augdal's avatar
Sigmund Augdal committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
die()
{
	log_failure_msg $1
	exit 1
}

start()
{
	. /opt/nova_router_services/bin/activate
	start-stop-daemon --start --pidfile "$PIDFILE" \
		--exec $EXE -- $args || return 2
	return 0
}

stop()
{
	if [ ! -f $PIDFILE ] ; then
		# This is a success according to LSB
		return 0
	fi
	start-stop-daemon --stop --pidfile "$PIDFILE"
	rm -f $PIDFILE
	return 0
}

status()
{
        if [ ! -f $PIDFILE ] ; then
                # program not running
                return 3
        fi

        for pid in $(cat $PIDFILE) ; do
                if ! ps --no-headers p "$pid"  | grep $EXE > /dev/null ; then
                        # program running, bogus pidfile
                        return 1
                fi
        done

        return 0
}

main()
{
	case "$1" in
		start)
			log_daemon_msg "Starting $NAME" "$NAME"
			start
			ret=$?
			case "$ret" in
				0)
					log_end_msg 0
					;;
				1)
					log_end_msg 1
					echo "pid file '$PIDFILE' found, $NAME not started."
					;;
				2)
					log_end_msg 1
					;;
			esac
			exit $ret
			;;
		stop)
			log_daemon_msg "Stopping $NAME" "$NAME"
			stop
			ret=$?
			case "$ret" in
				0|1)
					log_end_msg 0
					;;
				2)
					log_end_msg 1
					;;
			esac
			exit $ret
			;;
		restart)
			log_daemon_msg "Restarting $NAME" "$NAME"
			stop
			start
			ret=$?
			case "$ret" in
				0)
					log_end_msg 0
					;;
				1)
					log_end_msg 1
					;;
				2)
					log_end_msg 1
					;;
			esac
			exit $ret
			;;
		status)
			status
			ret=$?
			case "$ret" in
				0)
					echo "$NAME is running."
					;;
				1)
					echo "$NAME dead, but $PIDFILE exists."
					;;
				*)
					echo "$NAME not running."
					;;
			esac
			exit $ret
			;;

		*)
			echo "Usage: /etc/init.d/$NAME {start|stop|reload|restart|status}"
			exit 2
			;;
	esac

	:
}