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