summaryrefslogtreecommitdiffstats
path: root/meta/recipes-connectivity/openssh/openssh/init
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-connectivity/openssh/openssh/init')
-rw-r--r--meta/recipes-connectivity/openssh/openssh/init115
1 files changed, 115 insertions, 0 deletions
diff --git a/meta/recipes-connectivity/openssh/openssh/init b/meta/recipes-connectivity/openssh/openssh/init
new file mode 100644
index 0000000..70d4a34
--- /dev/null
+++ b/meta/recipes-connectivity/openssh/openssh/init
@@ -0,0 +1,115 @@
1#! /bin/sh
2set -e
3
4PIDFILE=/var/run/sshd.pid
5
6# source function library
7. /etc/init.d/functions
8
9# /etc/init.d/ssh: start and stop the OpenBSD "secure shell" daemon
10
11test -x /usr/sbin/sshd || exit 0
12( /usr/sbin/sshd -\? 2>&1 | grep -q OpenSSH ) 2>/dev/null || exit 0
13
14# /etc/default/ssh may set SYSCONFDIR and SSHD_OPTS
15if test -f /etc/default/ssh; then
16 . /etc/default/ssh
17fi
18
19[ -z "$SYSCONFDIR" ] && SYSCONFDIR=/etc/ssh
20mkdir -p $SYSCONFDIR
21
22HOST_KEY_RSA=$SYSCONFDIR/ssh_host_rsa_key
23HOST_KEY_DSA=$SYSCONFDIR/ssh_host_dsa_key
24HOST_KEY_ECDSA=$SYSCONFDIR/ssh_host_ecdsa_key
25HOST_KEY_ED25519=$SYSCONFDIR/ssh_host_ed25519_key
26
27check_for_no_start() {
28 # forget it if we're trying to start, and /etc/ssh/sshd_not_to_be_run exists
29 if [ -e $SYSCONFDIR/sshd_not_to_be_run ]; then
30 echo "OpenBSD Secure Shell server not in use ($SYSCONFDIR/sshd_not_to_be_run)"
31 exit 0
32 fi
33}
34
35check_privsep_dir() {
36 # Create the PrivSep empty dir if necessary
37 if [ ! -d /var/run/sshd ]; then
38 mkdir /var/run/sshd
39 chmod 0755 /var/run/sshd
40 fi
41}
42
43check_config() {
44 /usr/sbin/sshd -t || exit 1
45}
46
47check_keys() {
48 # create keys if necessary
49 if [ ! -f $HOST_KEY_RSA ]; then
50 echo " generating ssh RSA key..."
51 ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa
52 fi
53 if [ ! -f $HOST_KEY_ECDSA ]; then
54 echo " generating ssh ECDSA key..."
55 ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa
56 fi
57 if [ ! -f $HOST_KEY_DSA ]; then
58 echo " generating ssh DSA key..."
59 ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa
60 fi
61 if [ ! -f $HOST_KEY_ED25519 ]; then
62 echo " generating ssh ED25519 key..."
63 ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519
64 fi
65}
66
67export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
68
69case "$1" in
70 start)
71 check_for_no_start
72 echo "Starting OpenBSD Secure Shell server: sshd"
73 check_keys
74 check_privsep_dir
75 start-stop-daemon -S -p $PIDFILE -x /usr/sbin/sshd -- $SSHD_OPTS
76 echo "done."
77 ;;
78 stop)
79 echo -n "Stopping OpenBSD Secure Shell server: sshd"
80 start-stop-daemon -K -p $PIDFILE -x /usr/sbin/sshd
81 echo "."
82 ;;
83
84 reload|force-reload)
85 check_for_no_start
86 check_keys
87 check_config
88 echo -n "Reloading OpenBSD Secure Shell server's configuration"
89 start-stop-daemon -K -p $PIDFILE -s 1 -x /usr/sbin/sshd
90 echo "."
91 ;;
92
93 restart)
94 check_keys
95 check_config
96 echo -n "Restarting OpenBSD Secure Shell server: sshd"
97 start-stop-daemon -K -p $PIDFILE --oknodo -x /usr/sbin/sshd
98 check_for_no_start
99 check_privsep_dir
100 sleep 2
101 start-stop-daemon -S -p $PIDFILE -x /usr/sbin/sshd -- $SSHD_OPTS
102 echo "."
103 ;;
104
105 status)
106 status /usr/sbin/sshd
107 exit $?
108 ;;
109
110 *)
111 echo "Usage: /etc/init.d/ssh {start|stop|status|reload|force-reload|restart}"
112 exit 1
113esac
114
115exit 0