#!/bin/sh
# Description: Start or stop the Webmin server

start=/etc/webmin/start
stop=/etc/webmin/stop
lockfile=/var/lock/subsys/webmin
confFile=/etc/webmin/miniserv.conf
pidFile=/var/webmin/miniserv.pid

case "$1" in
'start')
	$start >/dev/null 2>&1 </dev/null
	RETVAL=$?
	if [ "$RETVAL" = "0" ]; then
		touch $lockfile >/dev/null 2>&1
		echo "Webmin Started"
	fi
	;;
'stop')
	$stop
	RETVAL=$?
	if [ "$RETVAL" = "0" ]; then
		rm -f $lockfile
	fi
	pidfile=`grep "^pidfile=" $confFile | sed -e 's/pidfile=//g'`
	if [ "$pidfile" = "" ]; then
		pidfile=$pidFile
	fi
	echo "Webmin Stopped"
	rm -f $pidfile
	;;
'status')
	pidfile=`grep "^pidfile=" $confFile | sed -e 's/pidfile=//g'`
	if [ "$pidfile" = "" ]; then
		pidfile=$pidFile
	fi
	if [ -s $pidfile ]; then
		pid=`cat $pidfile`
		kill -0 $pid >/dev/null 2>&1
		if [ "$?" = "0" ]; then
			echo "Webmin (pid $pid) is running"
			RETVAL=0
		else
			echo "Webmin is stopped"
			RETVAL=1
		fi
	else
		echo "Webmin is stopped"
		RETVAL=1
	fi
	;;
'restart')
	$stop ; $start
	RETVAL=$?
	;;
*)
	echo "Usage: $0 { start | stop | restart }"
	RETVAL=1
	;;
esac
exit $RETVAL
