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