#! /bin/sh
set -e

# /etc/init.d/remote-tty; start/stop the remote-tty serial console manager

test -x /usr/sbin/ttysrv || exit 0

case "$1" in
  start)
        echo "Starting remote-tty console manager:"
	cd /etc/remote-tty/dev
	if [ ! "x`ls`" == x ]; then
		su rttymgr -c "/usr/sbin/startsrv *"
	else
		echo "  no consoles configured."
	fi
	;;
  stop)
        echo -n "Stopping remote-tty console manager:"
	cd /var/run/remote-tty/pid
	for i in *; do
		if [ -f $i ]; then
			echo -n " $i"
			if start-stop-daemon --stop --quiet --oknodo \
					--pidfile /var/run/remote-tty/pid/$i;
					then
				rm -f $i
				rm -f /var/run/remote-tty/sock/$i
			fi
		else
			echo -n " nothing running"
		fi
	done
        echo "."
	;;
  restart|force-reload)
  	sh $0 stop
	sleep 5
	sh $0 start
	;;
  *)
	echo "Usage: /etc/init.d/ssh {start|stop}"
	exit 1
esac

exit 0
