summaryrefslogtreecommitdiff
path: root/debian/openssh-server.ssh.init
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2013-05-22 01:45:40 +0100
committerColin Watson <cjwatson@debian.org>2013-05-22 01:45:40 +0100
commit6e950945da7a2acbb48fa4138208018f09d66991 (patch)
tree1e99c1fb54755277a8c441cf503b71bb2c5be748 /debian/openssh-server.ssh.init
parentafd3292952a9f0bb107046785ddcfad446d69b89 (diff)
Switch to new unified layout for Upstart jobs as documented in
https://wiki.ubuntu.com/UpstartCompatibleInitScripts: the init script checks for a running Upstart, and we now let dh_installinit handle most of the heavy lifting in maintainer scripts. Ubuntu users should be essentially unaffected except that sshd may no longer start automatically in chroots if the running Upstart predates 0.9.0; but the main goal is simply not to break when openssh-server is installed in a chroot.
Diffstat (limited to 'debian/openssh-server.ssh.init')
-rw-r--r--debian/openssh-server.ssh.init174
1 files changed, 174 insertions, 0 deletions
diff --git a/debian/openssh-server.ssh.init b/debian/openssh-server.ssh.init
new file mode 100644
index 000000000..bda7a92b8
--- /dev/null
+++ b/debian/openssh-server.ssh.init
@@ -0,0 +1,174 @@
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_upstart() {
37 if init_is_upstart; then
38 exit $1
39 fi
40}
41
42check_for_no_start() {
43 # forget it if we're trying to start, and /etc/ssh/sshd_not_to_be_run exists
44 if [ -e /etc/ssh/sshd_not_to_be_run ]; then
45 if [ "$1" = log_end_msg ]; then
46 log_end_msg 0 || true
47 fi
48 if ! run_by_init; then
49 log_action_msg "OpenBSD Secure Shell server not in use (/etc/ssh/sshd_not_to_be_run)" || true
50 fi
51 exit 0
52 fi
53}
54
55check_dev_null() {
56 if [ ! -c /dev/null ]; then
57 if [ "$1" = log_end_msg ]; then
58 log_end_msg 1 || true
59 fi
60 if ! run_by_init; then
61 log_action_msg "/dev/null is not a character device!" || true
62 fi
63 exit 1
64 fi
65}
66
67check_privsep_dir() {
68 # Create the PrivSep empty dir if necessary
69 if [ ! -d /var/run/sshd ]; then
70 mkdir /var/run/sshd
71 chmod 0755 /var/run/sshd
72 fi
73}
74
75check_config() {
76 if [ ! -e /etc/ssh/sshd_not_to_be_run ]; then
77 /usr/sbin/sshd $SSHD_OPTS -t || exit 1
78 fi
79}
80
81export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
82
83case "$1" in
84 start)
85 check_for_upstart 1
86 check_privsep_dir
87 check_for_no_start
88 check_dev_null
89 log_daemon_msg "Starting OpenBSD Secure Shell server" "sshd" || true
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 || true
92 else
93 log_end_msg 1 || true
94 fi
95 ;;
96 stop)
97 check_for_upstart 0
98 log_daemon_msg "Stopping OpenBSD Secure Shell server" "sshd" || true
99 if start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/sshd.pid; then
100 log_end_msg 0 || true
101 else
102 log_end_msg 1 || true
103 fi
104 ;;
105
106 reload|force-reload)
107 check_for_upstart 1
108 check_for_no_start
109 check_config
110 log_daemon_msg "Reloading OpenBSD Secure Shell server's configuration" "sshd" || true
111 if start-stop-daemon --stop --signal 1 --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd; then
112 log_end_msg 0 || true
113 else
114 log_end_msg 1 || true
115 fi
116 ;;
117
118 restart)
119 check_for_upstart 1
120 check_privsep_dir
121 check_config
122 log_daemon_msg "Restarting OpenBSD Secure Shell server" "sshd" || true
123 start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile /var/run/sshd.pid
124 check_for_no_start log_end_msg
125 check_dev_null log_end_msg
126 if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS; then
127 log_end_msg 0 || true
128 else
129 log_end_msg 1 || true
130 fi
131 ;;
132
133 try-restart)
134 check_for_upstart 1
135 check_privsep_dir
136 check_config
137 log_daemon_msg "Restarting OpenBSD Secure Shell server" "sshd" || true
138 RET=0
139 start-stop-daemon --stop --quiet --retry 30 --pidfile /var/run/sshd.pid || RET="$?"
140 case $RET in
141 0)
142 # old daemon stopped
143 check_for_no_start log_end_msg
144 check_dev_null log_end_msg
145 if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS; then
146 log_end_msg 0 || true
147 else
148 log_end_msg 1 || true
149 fi
150 ;;
151 1)
152 # daemon not running
153 log_progress_msg "(not running)" || true
154 log_end_msg 0 || true
155 ;;
156 *)
157 # failed to stop
158 log_progress_msg "(failed to stop)" || true
159 log_end_msg 1 || true
160 ;;
161 esac
162 ;;
163
164 status)
165 check_for_upstart 1
166 status_of_proc -p /var/run/sshd.pid /usr/sbin/sshd sshd && exit 0 || exit $?
167 ;;
168
169 *)
170 log_action_msg "Usage: /etc/init.d/ssh {start|stop|reload|force-reload|restart|try-restart|status}" || true
171 exit 1
172esac
173
174exit 0