#!/bin/sh

# Bring up/down sshd

. /etc/sysconfig/rc.conf
. /bin/network-functions

SETSID=/usr/bin/setsid
PIDFILE=/var/run/sshd.pid
SERVICE=sshd
PROCESS_NAME=sshd

KILLALL=/usr/bin/killall

do_start ()
{
	if ! ServiceCheckRunning1 ; then
		return $?
	fi

	adduser -M sshd
	mkdir -p /var/empty/sshd
	
	/etc/init.d/softdogd wait
	$SETSID /bin/$PROCESS_NAME >/dev/null 2>/dev/null
	ServiceCheckRunning2

	return $?
}

do_stop ()
{
	local RESULT;

	/etc/init.d/softdogd wait
	ServiceStop
	RESULT=$?
	rm -fr /var/empty/sshd
	userdel -f sshd
#	/bin/sleep 2
#	$KILLALL -9 sshd

	return $RESULT
}

do_status ()
{
	local SSHDSTATUS;

	ServiceStatus
	SSHDSTATUS=$?

	return $SSHDSTATUS
}

case "$1" in
	start)
		do_start
		;;
	stop)
		do_stop
		;;
	status)
		do_status
		;;
	slow_restart)
		/bin/sleep 5
		do_stop
		do_start
		;;
	restart)
		do_stop
		do_start
		;;
	*)
		echo "Usage: $0 {start|stop|status|restart|slow_restart}"
		exit 1
esac

exit $?
