#!/bin/sh
#
#
# chkconfig: 345 40 60
# description: Mandriva Server Setup Agent

### BEGIN INIT INFO
# Provides: mss-agent
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 4 5
# Default-Stop: 0 1 6
# Short-Description: ROSA Server Setup Agent
# Description: Wizard for MDS/Pulse 2 setup and server stacks installation
### END INIT INFO

. /etc/rc.d/init.d/functions
[ -r /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n
export LC_ALL
export LANG

prog=mss-agent
PIDFILE=/var/run/$prog.pid

function start () {
    printf "Starting %s: " "$prog"
    if [ -f /var/lock/subsys/$prog ]; then
        printf "%s is already running" "$prog" && success
	
    else
	/usr/sbin/mss-agent.py start
	# wait pid file to be created
	sleep 1
	touch /var/lock/subsys/$prog
	[ -f /var/run/$prog.pid ] && success || failure
    fi
    echo
}

function stop () {
    printf "Stopping %s: " "$prog"
    if [ -f /var/lock/subsys/$prog ]; then
        /usr/sbin/mss-agent.py stop
        sleep 1
	[ -f /var/lock/subsys/$prog ] && rm -f /var/lock/subsys/$prog        
        [ -f $PIDFILE ] && failure || success
    else
	printf "$prog is not running" && success
    fi
    echo
}

case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    status)
	status mss-agent.py
	;;
    restart)
	stop
	start
	;;
    reload)
	stop
	start
	;;
    status)
	status -p $PIDFILE
	;;
    *)
	printf "Usage: $0 {start|stop|status|restart}\n"
	exit 1
esac

