#!/bin/dash

DAEMON=sshd
DAEMON_BIN=/usr/sbin/sshd

is_up() {
	pidof $DAEMON > /dev/null
}

start() {
	if ! is_up; then
		$DAEMON_BIN
		echo $DAEMON started
	fi
}

stop() {
	if is_up; then
		killall $DAEMON
		echo $DAEMON stopped
	fi
}

reload() {
	if is_up; then
		killall -HUP $DAEMON
		echo $DAEMON configuration reloaded
	else
		echo $DAEMON is not running
	fi
}

### main
case $1 in
	start) start ;;
	stop) stop ;;
	status) is_up && echo "$DAEMON is running" || echo "$DAEMON is stopped" ;;
	reload) reload ;;
	restart) stop; sleep 1; start ;;
esac
