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