3 # sshd Start up the OpenSSH server daemon
5 # chkconfig: 2345 55 25
6 # description: SSH is a protocol for secure remote shell access. \
7 # This service starts up the OpenSSH server daemon.
10 # config: /etc/ssh/ssh_host_key
11 # config: /etc/ssh/ssh_host_key.pub
12 # config: /etc/ssh/ssh_random_seed
13 # config: /etc/ssh/sshd_config
14 # pidfile: /var/run/sshd.pid
18 # Required-Start: $local_fs $network $syslog
19 # Required-Stop: $local_fs $syslog
20 # Should-Start: $syslog
21 # Should-Stop: $network $syslog
22 # Default-Start: 2 3 4 5
24 # Short-Description: Start up the OpenSSH server daemon
25 # Description: SSH is a protocol for secure remote shell access.
26 # This service starts up the OpenSSH server daemon.
29 # source function library
30 . /etc/init.d/functions
32 # pull in sysconfig settings
33 [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
37 lockfile=/var/lock/subsys/$prog
39 # Some functions to make the below more readable
41 XPID_FILE=/var/run/sshd.pid
42 PID_FILE=/var/run/sshd-s.pid
44 runlevel=$(set -- $(runlevel); eval "echo \$$#" )
46 do_restart_sanity_check()
50 if [ $RETVAL -ne 0 ]; then
51 failure $"Configuration file or keys are invalid"
58 [ -x $SSHD ] || exit 5
59 [ -f /etc/ssh/sshd_config ] || exit 6
60 # Create keys if necessary
63 # In rare instances, sshd may be started but a pid
64 # file is not generated. This is seen usually during
65 # system reboot scenarios. A subsequent attempt to start
66 # sshd here will trigger a port bind error. As a sanity
67 # check attempt a kill call (mostly redundant) to any
68 # previously running sshd instance
69 /bin/kill `/bin/pidof "$SSHD"` >/dev/null 2>&1
71 echo -n $"Starting $prog: "
72 $SSHD $OPTIONS && success || failure
74 [ $RETVAL -eq 0 ] && touch $lockfile
75 [ $RETVAL -eq 0 ] && cp -f $XPID_FILE $PID_FILE
83 echo -n $"Stopping $prog: "
84 if [ ! -f "$PID_FILE" ]; then
85 # not running; per LSB standards this is "ok"
86 action $"Stopping $prog: " /bin/true
90 if [ -n "$PID" ]; then
91 /bin/kill "$PID" >/dev/null 2>&1
93 if [ $RETVAL -eq 0 ]; then
95 action $"Stopping $prog: " /bin/false
97 action $"Stopping $prog: " /bin/true
100 # failed to read pidfile
101 action $"Stopping $prog: " /bin/false
104 # if we are in halt or reboot runlevel kill all running sessions
105 # so the TCP connections are closed cleanly
106 if [ "x$runlevel" = x0 -o "x$runlevel" = x6 ] ; then
108 killall $prog 2>/dev/null
111 [ $RETVAL -eq 0 ] && rm -f $lockfile
118 echo -n $"Reloading $prog: "
119 if [ -n "`pidfileofproc $SSHD`" ] ; then
122 failure $"Reloading $prog"
138 status -p $PID_FILE openssh-daemon
142 rh_status >/dev/null 2>&1
147 rh_status_q && exit 0
151 if ! rh_status_q; then
161 rh_status_q || exit 7
167 condrestart|try-restart)
168 rh_status_q || exit 0
169 if [ -f $lockfile ] ; then
170 do_restart_sanity_check
171 if [ $RETVAL -eq 0 ] ; then
184 if [ $RETVAL -eq 3 -a -f $lockfile ] ; then
189 echo $"Usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}"