- (tim) [openbsd-compat/glob.h] Remove sys/cdefs.h include that came with
[openssh-git.git] / contrib / suse / rc.sshd
blob4d4880d7ed60438f5afe8025f88000d28a6e74f5
1 #! /bin/sh
2 # Copyright (c) 1995-2000 SuSE GmbH Nuernberg, Germany.
4 # Author: Jiri Smid <feedback@suse.de>
6 # /etc/init.d/sshd
8 # and symbolic its link
10 # /usr/sbin/rcsshd
12 ### BEGIN INIT INFO
13 # Provides: sshd
14 # Required-Start: $network $remote_fs
15 # Required-Stop: $network $remote_fs
16 # Default-Start: 3 5
17 # Default-Stop: 0 1 2 6
18 # Description: Start the sshd daemon
19 ### END INIT INFO
21 SSHD_BIN=/usr/sbin/sshd
22 test -x $SSHD_BIN || exit 5
24 SSHD_SYSCONFIG=/etc/sysconfig/ssh
25 test -r $SSHD_SYSCONFIG || exit 6
26 . $SSHD_SYSCONFIG
28 SSHD_PIDFILE=/var/run/sshd.init.pid
30 . /etc/rc.status
32 # Shell functions sourced from /etc/rc.status:
33 # rc_check check and set local and overall rc status
34 # rc_status check and set local and overall rc status
35 # rc_status -v ditto but be verbose in local rc status
36 # rc_status -v -r ditto and clear the local rc status
37 # rc_failed set local and overall rc status to failed
38 # rc_reset clear local rc status (overall remains)
39 # rc_exit exit appropriate to overall rc status
41 # First reset status of this service
42 rc_reset
44 case "$1" in
45 start)
46 if ! test -f /etc/ssh/ssh_host_key ; then
47 echo Generating /etc/ssh/ssh_host_key.
48 ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key -N ''
50 if ! test -f /etc/ssh/ssh_host_dsa_key ; then
51 echo Generating /etc/ssh/ssh_host_dsa_key.
53 ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
55 if ! test -f /etc/ssh/ssh_host_rsa_key ; then
56 echo Generating /etc/ssh/ssh_host_rsa_key.
58 ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
60 echo -n "Starting SSH daemon"
61 ## Start daemon with startproc(8). If this fails
62 ## the echo return value is set appropriate.
64 startproc -f -p $SSHD_PIDFILE /usr/sbin/sshd $SSHD_OPTS -o "PidFile=$SSHD_PIDFILE"
66 # Remember status and be verbose
67 rc_status -v
69 stop)
70 echo -n "Shutting down SSH daemon"
71 ## Stop daemon with killproc(8) and if this fails
72 ## set echo the echo return value.
74 killproc -p $SSHD_PIDFILE -TERM /usr/sbin/sshd
76 # Remember status and be verbose
77 rc_status -v
79 try-restart)
80 ## Stop the service and if this succeeds (i.e. the
81 ## service was running before), start it again.
82 $0 status >/dev/null && $0 restart
84 # Remember status and be quiet
85 rc_status
87 restart)
88 ## Stop the service and regardless of whether it was
89 ## running or not, start it again.
90 $0 stop
91 $0 start
93 # Remember status and be quiet
94 rc_status
96 force-reload|reload)
97 ## Signal the daemon to reload its config. Most daemons
98 ## do this on signal 1 (SIGHUP).
100 echo -n "Reload service sshd"
102 killproc -p $SSHD_PIDFILE -HUP /usr/sbin/sshd
104 rc_status -v
107 status)
108 echo -n "Checking for service sshd "
109 ## Check status with checkproc(8), if process is running
110 ## checkproc will return with exit status 0.
112 # Status has a slightly different for the status command:
113 # 0 - service running
114 # 1 - service dead, but /var/run/ pid file exists
115 # 2 - service dead, but /var/lock/ lock file exists
116 # 3 - service not running
118 checkproc -p $SSHD_PIDFILE /usr/sbin/sshd
120 rc_status -v
122 probe)
123 ## Optional: Probe for the necessity of a reload,
124 ## give out the argument which is required for a reload.
126 test /etc/ssh/sshd_config -nt $SSHD_PIDFILE && echo reload
129 echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
130 exit 1
132 esac
133 rc_exit