5 # Required-Start: $remote_fs $syslog
6 # Required-Stop: $remote_fs $syslog
7 # Default-Start: 2 3 4 5
9 # Short-Description: OpenBSD Secure Shell server
14 # /etc/init.d/ssh: start and stop the OpenBSD "secure shell(tm)" daemon
16 test -x /usr/sbin/sshd || exit 0
20 export SSHD_OOM_ADJUST=-17
21 if test -f /etc/default/ssh; then
25 # Are we in a virtual environment that doesn't support modifying
27 if grep -q 'envID:.*[1-9]' /proc/self/status; then
31 . /lib/lsb/init-functions
34 SSHD_OPTS="$SSHD_OPTS $2"
37 # Are we running from init?
39 ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ]
42 check_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
48 if ! run_by_init; then
49 log_action_msg "OpenBSD Secure Shell server not in use (/etc/ssh/sshd_not_to_be_run)"
56 if [ ! -c /dev/null ]; then
57 if [ "$1" = log_end_msg ]; then
60 if ! run_by_init; then
61 log_action_msg "/dev/null is not a character device!"
68 # Create the PrivSep empty dir if necessary
69 if [ ! -d /var/run/sshd ]; then
71 chmod 0755 /var/run/sshd
76 if [ ! -e /etc/ssh/sshd_not_to_be_run ]; then
77 /usr/sbin/sshd $SSHD_OPTS -t || exit 1
81 export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
88 log_daemon_msg "Starting OpenBSD Secure Shell server" "sshd"
89 if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS; then
96 log_daemon_msg "Stopping OpenBSD Secure Shell server" "sshd"
97 if start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/sshd.pid; then
107 log_daemon_msg "Reloading OpenBSD Secure Shell server's configuration" "sshd"
108 if start-stop-daemon --stop --signal 1 --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd; then
118 log_daemon_msg "Restarting OpenBSD Secure Shell server" "sshd"
119 start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile /var/run/sshd.pid
120 check_for_no_start log_end_msg
121 check_dev_null log_end_msg
122 if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS; then
132 log_daemon_msg "Restarting OpenBSD Secure Shell server" "sshd"
134 start-stop-daemon --stop --quiet --retry 30 --pidfile /var/run/sshd.pid
140 check_for_no_start log_end_msg
141 check_dev_null log_end_msg
142 if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS; then
150 log_progress_msg "(not running)"
155 log_progress_msg "(failed to stop)"
162 status_of_proc -p /var/run/sshd.pid /usr/sbin/sshd sshd && exit 0 || exit $?
166 log_action_msg "Usage: /etc/init.d/ssh {start|stop|reload|force-reload|restart|try-restart|status}"