summaryrefslogtreecommitdiff
path: root/debian/openssh-server.ssh.init
diff options
context:
space:
mode:
Diffstat (limited to 'debian/openssh-server.ssh.init')
-rwxr-xr-xdebian/openssh-server.ssh.init162
1 files changed, 162 insertions, 0 deletions
diff --git a/debian/openssh-server.ssh.init b/debian/openssh-server.ssh.init
new file mode 100755
index 000000000..620af70e0
--- /dev/null
+++ b/debian/openssh-server.ssh.init
@@ -0,0 +1,162 @@
1#! /bin/sh
2
3### BEGIN INIT INFO
4# Provides: sshd
5# Required-Start: $remote_fs $syslog
6# Required-Stop: $remote_fs $syslog
7# Default-Start: 2 3 4 5
8# Default-Stop:
9# Short-Description: OpenBSD Secure Shell server
10### END INIT INFO
11
12set -e
13
14# /etc/init.d/ssh: start and stop the OpenBSD "secure shell(tm)" daemon
15
16test -x /usr/sbin/sshd || exit 0
17( /usr/sbin/sshd -\? 2>&1 | grep -q OpenSSH ) 2>/dev/null || exit 0
18
19umask 022
20
21if test -f /etc/default/ssh; then
22 . /etc/default/ssh
23fi
24
25. /lib/lsb/init-functions
26
27if [ -n "$2" ]; then
28 SSHD_OPTS="$SSHD_OPTS $2"
29fi
30
31# Are we running from init?
32run_by_init() {
33 ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ]
34}
35
36check_for_no_start() {
37 # forget it if we're trying to start, and /etc/ssh/sshd_not_to_be_run exists
38 if [ -e /etc/ssh/sshd_not_to_be_run ]; then
39 if [ "$1" = log_end_msg ]; then
40 log_end_msg 0 || true
41 fi
42 if ! run_by_init; then
43 log_action_msg "OpenBSD Secure Shell server not in use (/etc/ssh/sshd_not_to_be_run)" || true
44 fi
45 exit 0
46 fi
47}
48
49check_dev_null() {
50 if [ ! -c /dev/null ]; then
51 if [ "$1" = log_end_msg ]; then
52 log_end_msg 1 || true
53 fi
54 if ! run_by_init; then
55 log_action_msg "/dev/null is not a character device!" || true
56 fi
57 exit 1
58 fi
59}
60
61check_privsep_dir() {
62 # Create the PrivSep empty dir if necessary
63 if [ ! -d /run/sshd ]; then
64 mkdir /run/sshd
65 chmod 0755 /run/sshd
66 fi
67}
68
69check_config() {
70 if [ ! -e /etc/ssh/sshd_not_to_be_run ]; then
71 /usr/sbin/sshd $SSHD_OPTS -t || exit 1
72 fi
73}
74
75export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
76
77case "$1" in
78 start)
79 check_privsep_dir
80 check_for_no_start
81 check_dev_null
82 log_daemon_msg "Starting OpenBSD Secure Shell server" "sshd" || true
83 if start-stop-daemon --start --quiet --oknodo --chuid 0:0 --pidfile /run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS; then
84 log_end_msg 0 || true
85 else
86 log_end_msg 1 || true
87 fi
88 ;;
89 stop)
90 log_daemon_msg "Stopping OpenBSD Secure Shell server" "sshd" || true
91 if start-stop-daemon --stop --quiet --oknodo --pidfile /run/sshd.pid --exec /usr/sbin/sshd; then
92 log_end_msg 0 || true
93 else
94 log_end_msg 1 || true
95 fi
96 ;;
97
98 reload|force-reload)
99 check_for_no_start
100 check_config
101 log_daemon_msg "Reloading OpenBSD Secure Shell server's configuration" "sshd" || true
102 if start-stop-daemon --stop --signal 1 --quiet --oknodo --pidfile /run/sshd.pid --exec /usr/sbin/sshd; then
103 log_end_msg 0 || true
104 else
105 log_end_msg 1 || true
106 fi
107 ;;
108
109 restart)
110 check_privsep_dir
111 check_config
112 log_daemon_msg "Restarting OpenBSD Secure Shell server" "sshd" || true
113 start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile /run/sshd.pid --exec /usr/sbin/sshd
114 check_for_no_start log_end_msg
115 check_dev_null log_end_msg
116 if start-stop-daemon --start --quiet --oknodo --chuid 0:0 --pidfile /run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS; then
117 log_end_msg 0 || true
118 else
119 log_end_msg 1 || true
120 fi
121 ;;
122
123 try-restart)
124 check_privsep_dir
125 check_config
126 log_daemon_msg "Restarting OpenBSD Secure Shell server" "sshd" || true
127 RET=0
128 start-stop-daemon --stop --quiet --retry 30 --pidfile /run/sshd.pid --exec /usr/sbin/sshd || RET="$?"
129 case $RET in
130 0)
131 # old daemon stopped
132 check_for_no_start log_end_msg
133 check_dev_null log_end_msg
134 if start-stop-daemon --start --quiet --oknodo --chuid 0:0 --pidfile /run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS; then
135 log_end_msg 0 || true
136 else
137 log_end_msg 1 || true
138 fi
139 ;;
140 1)
141 # daemon not running
142 log_progress_msg "(not running)" || true
143 log_end_msg 0 || true
144 ;;
145 *)
146 # failed to stop
147 log_progress_msg "(failed to stop)" || true
148 log_end_msg 1 || true
149 ;;
150 esac
151 ;;
152
153 status)
154 status_of_proc -p /run/sshd.pid /usr/sbin/sshd sshd && exit 0 || exit $?
155 ;;
156
157 *)
158 log_action_msg "Usage: /etc/init.d/ssh {start|stop|reload|force-reload|restart|try-restart|status}" || true
159 exit 1
160esac
161
162exit 0