Home | History | Annotate | Download | only in suse
      1 #! /bin/sh
      2 # Copyright (c) 1995-2000 SuSE GmbH Nuernberg, Germany.
      3 #
      4 # Author: Jiri Smid <feedback (at] suse.de>
      5 #
      6 # /etc/init.d/sshd
      7 #
      8 #   and symbolic its link
      9 #
     10 # /usr/sbin/rcsshd
     11 #
     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
     20 
     21 SSHD_BIN=/usr/sbin/sshd
     22 test -x $SSHD_BIN || exit 5
     23 
     24 SSHD_SYSCONFIG=/etc/sysconfig/ssh
     25 test -r $SSHD_SYSCONFIG || exit 6
     26 . $SSHD_SYSCONFIG
     27 
     28 SSHD_PIDFILE=/var/run/sshd.init.pid
     29 
     30 . /etc/rc.status
     31 
     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
     40 
     41 # First reset status of this service
     42 rc_reset
     43 
     44 case "$1" in
     45     start)
     46 	# Generate any missing host keys
     47 	ssh-keygen -A
     48 	echo -n "Starting SSH daemon"
     49 	## Start daemon with startproc(8). If this fails
     50 	## the echo return value is set appropriate.
     51 
     52 	startproc -f -p $SSHD_PIDFILE /usr/sbin/sshd $SSHD_OPTS -o "PidFile=$SSHD_PIDFILE" 
     53 
     54 	# Remember status and be verbose
     55 	rc_status -v
     56 	;;
     57     stop)
     58 	echo -n "Shutting down SSH daemon"
     59 	## Stop daemon with killproc(8) and if this fails
     60 	## set echo the echo return value.
     61 
     62 	killproc -p $SSHD_PIDFILE -TERM /usr/sbin/sshd
     63 
     64 	# Remember status and be verbose
     65 	rc_status -v
     66 	;;
     67     try-restart)
     68         ## Stop the service and if this succeeds (i.e. the 
     69         ## service was running before), start it again.
     70         $0 status >/dev/null &&  $0 restart
     71 
     72         # Remember status and be quiet
     73         rc_status
     74         ;;
     75     restart)
     76         ## Stop the service and regardless of whether it was
     77         ## running or not, start it again.
     78         $0 stop
     79         $0 start
     80 
     81         # Remember status and be quiet
     82         rc_status
     83         ;;
     84     force-reload|reload)
     85 	## Signal the daemon to reload its config. Most daemons
     86 	## do this on signal 1 (SIGHUP).
     87 
     88 	echo -n "Reload service sshd"
     89 
     90 	killproc -p $SSHD_PIDFILE -HUP /usr/sbin/sshd
     91 
     92         rc_status -v
     93 
     94         ;;
     95     status)
     96 	echo -n "Checking for service sshd "
     97         ## Check status with checkproc(8), if process is running
     98         ## checkproc will return with exit status 0.
     99 
    100         # Status has a slightly different for the status command:
    101         # 0 - service running
    102         # 1 - service dead, but /var/run/  pid  file exists
    103         # 2 - service dead, but /var/lock/ lock file exists
    104         # 3 - service not running
    105 
    106 	checkproc -p $SSHD_PIDFILE /usr/sbin/sshd
    107 
    108 	rc_status -v
    109 	;;
    110     probe)
    111 	## Optional: Probe for the necessity of a reload,
    112 	## give out the argument which is required for a reload.
    113 
    114         test /etc/ssh/sshd_config -nt $SSHD_PIDFILE && echo reload
    115 	;;
    116     *)
    117 	echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
    118 	exit 1
    119 	;;
    120 esac
    121 rc_exit
    122