#!/bin/sh
#
# webmin        Start Webmin remote administration tool. This script
#               starts the Webmin server.
#
# chkconfig: 2345 99 00
#
# description: Webmin is a remote administration tool using web-browser
# processname: perl
# pidfile: /var/webmin/miniserv.pid
# config: /etc/webmin/miniserv.conf
# config: /etc/webmin/miniserv.users

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

if [ ! -d /etc/webmin ] || [ -f /etc/webmin/postinstall_pending ]
then /usr/share/webmin/postinstall.sh
fi

[ -d /usr/share/webmin ] && [ -d /etc/webmin ] || exit 0

if [ ! -f /etc/webmin/start ] || [ ! -f /etc/webmin/stop ]
then echo "Warning, Webmin installation failed"
exit -1
fi

# See how we were called.
case "$1" in
  start)
	action "Starting Webmin: " /etc/webmin/start
	[ $? -eq 0 ] && touch /var/lock/subsys/webmin
	;;
  stop)
	action "Stopping Webmin: " /etc/webmin/stop
	[ $? -eq 0 ] && rm -f /var/lock/subsys/webmin
	;;
  status)
	if ! [ -f /var/webmin/miniserv.pid ]
	then echo "miniserv.pl is stopped"
		exit 3
	fi
	pid=`cat /var/webmin/miniserv.pid`
	kill -0 $pid >/dev/null 2>&1
	if [ $? == 0 ]
	then echo "miniserv.pl (pid $pid) is running..."
		exit 0
	fi
	echo "miniserv.pl is stopped"
	exit 3
	;;
  restart)
	$0 stop
	$0 start
	;;
  reload)
	$0 stop
	$0 start
	;;
  condrestart)
	if [ -f /var/lock/subsys/webmin ]; then
		$0 stop
		$0 start
	fi
	;;
  *)
	echo "Usage: $0 { start | stop | status | restart | condrestart }"
	exit 1
	;;
esac

exit 0
