diff network/openssh/sshd @ 121:f2c94d482098

network/openssh: initial import, closes #1156
author David Demelier <markand@malikania.fr>
date Sun, 10 Mar 2019 11:49:40 +0100
parents
children 9f90de3d806f
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/network/openssh/sshd	Sun Mar 10 11:49:40 2019 +0100
@@ -0,0 +1,72 @@
+#!/bin/sh
+#
+# /etc/rc.d/sshd: run control script for sshd
+
+if [ -f /etc/rc.conf ]; then
+	source /etc/rc.conf
+fi
+
+: ${SSHD_CMD:=/usr/sbin/sshd}
+: ${SSHD_ARGS:=}
+: ${SSHD_PID:=/var/run/sshd.pid}
+
+sshd_start()
+{
+	if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
+		/usr/bin/ssh-keygen -q -t rsa -b 2048 -N "" -f /etc/ssh/ssh_host_rsa_key
+	fi
+	if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then
+		/usr/bin/ssh-keygen -q -t dsa -N "" -f /etc/ssh/ssh_host_dsa_key
+	fi
+	if [ ! -f /etc/ssh/ssh_host_ecdsa_key ]; then
+		/usr/bin/ssh-keygen -q -t ecdsa -b 521 -N "" -f /etc/ssh/ssh_host_ecdsa_key
+	fi
+	if [ ! -f /etc/ssh/ssh_host_ed25519_key ]; then
+		/usr/bin/ssh-keygen -q -t ed25519 -N "" -f /etc/ssh/ssh_host_ed25519_key
+	fi
+
+	echo "Starting sshd: $SSHD_CMD $SSHD_ARGS"
+	$SSHD_CMD $SSHD_ARGS -p $SSHD_PID
+}
+
+sshd_status()
+{
+	if [ -s $SSHD_PID ]; then
+		echo "sshd is running with pid: `cat $SSHD_PID`"
+	else
+		echo "sshd is not running"
+	fi
+}
+
+sshd_stop()
+{
+	if [ -s $SSHD_PID ]; then
+		echo "Stopping sshd..."
+		kill -QUIT $SSHD_PID
+	fi
+}
+
+sshd_restart()
+{
+	sshd_stop
+	sleep 3
+	sshd_start
+}
+
+case $1 in
+start)
+	sshd_start
+	;;
+status)
+	sshd_status
+	;;
+stop)
+	sshd_stop
+	;;
+restart)
+	sshd_restart
+	;;
+*)
+	echo "usage: $(basename $0) restart|start|status|stop"
+	;;
+esac