rc.sshd revision 180740
197403Sobrien#! /bin/sh 297403Sobrien# Copyright (c) 1995-2000 SuSE GmbH Nuernberg, Germany. 397403Sobrien# 497403Sobrien# Author: Jiri Smid <feedback@suse.de> 597403Sobrien# 697403Sobrien# /etc/init.d/sshd 797403Sobrien# 897403Sobrien# and symbolic its link 997403Sobrien# 1097403Sobrien# /usr/sbin/rcsshd 1197403Sobrien# 1297403Sobrien### BEGIN INIT INFO 1397403Sobrien# Provides: sshd 1497403Sobrien# Required-Start: $network $remote_fs 1597403Sobrien# Required-Stop: $network $remote_fs 1697403Sobrien# Default-Start: 3 5 1797403Sobrien# Default-Stop: 0 1 2 6 1897403Sobrien# Description: Start the sshd daemon 1997403Sobrien### END INIT INFO 2097403Sobrien 2197403SobrienSSHD_BIN=/usr/sbin/sshd 2297403Sobrientest -x $SSHD_BIN || exit 5 2397403Sobrien 2497403SobrienSSHD_SYSCONFIG=/etc/sysconfig/ssh 2597403Sobrientest -r $SSHD_SYSCONFIG || exit 6 2697403Sobrien. $SSHD_SYSCONFIG 2797403Sobrien 2897403SobrienSSHD_PIDFILE=/var/run/sshd.init.pid 2997403Sobrien 3097403Sobrien. /etc/rc.status 3197403Sobrien 3297403Sobrien# Shell functions sourced from /etc/rc.status: 3397403Sobrien# rc_check check and set local and overall rc status 3497403Sobrien# rc_status check and set local and overall rc status 3597403Sobrien# rc_status -v ditto but be verbose in local rc status 3697403Sobrien# rc_status -v -r ditto and clear the local rc status 3797403Sobrien# rc_failed set local and overall rc status to failed 3897403Sobrien# rc_reset clear local rc status (overall remains) 3997403Sobrien# rc_exit exit appropriate to overall rc status 4097403Sobrien 41110614Skan# First reset status of this service 42110614Skanrc_reset 43110614Skan 4497403Sobriencase "$1" in 45107606Sobrien start) 46107606Sobrien if ! test -f /etc/ssh/ssh_host_key ; then 47107606Sobrien echo Generating /etc/ssh/ssh_host_key. 48107606Sobrien ssh-keygen -t rsa1 -b 1024 -f /etc/ssh/ssh_host_key -N '' 49107606Sobrien fi 50107606Sobrien if ! test -f /etc/ssh/ssh_host_dsa_key ; then 51107606Sobrien echo Generating /etc/ssh/ssh_host_dsa_key. 52107606Sobrien 53107606Sobrien ssh-keygen -t dsa -b 1024 -f /etc/ssh/ssh_host_dsa_key -N '' 54107606Sobrien fi 55107606Sobrien if ! test -f /etc/ssh/ssh_host_rsa_key ; then 56107606Sobrien echo Generating /etc/ssh/ssh_host_rsa_key. 57107606Sobrien 58107606Sobrien ssh-keygen -t rsa -b 1024 -f /etc/ssh/ssh_host_rsa_key -N '' 5997403Sobrien fi 6097403Sobrien echo -n "Starting SSH daemon" 61107606Sobrien ## Start daemon with startproc(8). If this fails 62107606Sobrien ## the echo return value is set appropriate. 6397403Sobrien 6497403Sobrien startproc -f -p $SSHD_PIDFILE /usr/sbin/sshd $SSHD_OPTS -o "PidFile=$SSHD_PIDFILE" 6597403Sobrien 6697403Sobrien # Remember status and be verbose 6797403Sobrien rc_status -v 6897403Sobrien ;; 6997403Sobrien stop) 7097403Sobrien echo -n "Shutting down SSH daemon" 7197403Sobrien ## Stop daemon with killproc(8) and if this fails 7297403Sobrien ## set echo the echo return value. 7397403Sobrien 7497403Sobrien killproc -p $SSHD_PIDFILE -TERM /usr/sbin/sshd 7597403Sobrien 7697403Sobrien # Remember status and be verbose 7797403Sobrien rc_status -v 7897403Sobrien ;; 7997403Sobrien try-restart) 8097403Sobrien ## Stop the service and if this succeeds (i.e. the 8197403Sobrien ## service was running before), start it again. 8297403Sobrien $0 status >/dev/null && $0 restart 8397403Sobrien 8497403Sobrien # Remember status and be quiet 8597403Sobrien rc_status 8697403Sobrien ;; 8797403Sobrien restart) 8897403Sobrien ## Stop the service and regardless of whether it was 8997403Sobrien ## running or not, start it again. 9097403Sobrien $0 stop 9197403Sobrien $0 start 9297403Sobrien 9397403Sobrien # Remember status and be quiet 9497403Sobrien rc_status 9597403Sobrien ;; 9697403Sobrien force-reload|reload) 9797403Sobrien ## Signal the daemon to reload its config. Most daemons 9897403Sobrien ## do this on signal 1 (SIGHUP). 9997403Sobrien 10097403Sobrien echo -n "Reload service sshd" 10197403Sobrien 10297403Sobrien killproc -p $SSHD_PIDFILE -HUP /usr/sbin/sshd 10397403Sobrien 10497403Sobrien rc_status -v 10597403Sobrien 10697403Sobrien ;; 10797403Sobrien status) 10897403Sobrien echo -n "Checking for service sshd " 10997403Sobrien ## Check status with checkproc(8), if process is running 11097403Sobrien ## checkproc will return with exit status 0. 11197403Sobrien 11297403Sobrien # Status has a slightly different for the status command: 11397403Sobrien # 0 - service running 11497403Sobrien # 1 - service dead, but /var/run/ pid file exists 11597403Sobrien # 2 - service dead, but /var/lock/ lock file exists 11697403Sobrien # 3 - service not running 11797403Sobrien 11897403Sobrien checkproc -p $SSHD_PIDFILE /usr/sbin/sshd 11997403Sobrien 12097403Sobrien rc_status -v 12197403Sobrien ;; 12297403Sobrien probe) 12397403Sobrien ## Optional: Probe for the necessity of a reload, 12497403Sobrien ## give out the argument which is required for a reload. 12597403Sobrien 12697403Sobrien test /etc/ssh/sshd_config -nt $SSHD_PIDFILE && echo reload 12797403Sobrien ;; 12897403Sobrien *) 12997403Sobrien echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}" 13097403Sobrien exit 1 13197403Sobrien ;; 13297403Sobrienesac 13397403Sobrienrc_exit 13497403Sobrien