rc.sshd revision 225825
1180740Sdes#! /bin/sh 2180740Sdes# Copyright (c) 1995-2000 SuSE GmbH Nuernberg, Germany. 3180740Sdes# 4180740Sdes# Author: Jiri Smid <feedback@suse.de> 5180740Sdes# 6180740Sdes# /etc/init.d/sshd 7180740Sdes# 8180740Sdes# and symbolic its link 9180740Sdes# 10180740Sdes# /usr/sbin/rcsshd 11180740Sdes# 12180740Sdes### BEGIN INIT INFO 13180740Sdes# Provides: sshd 14180740Sdes# Required-Start: $network $remote_fs 15180740Sdes# Required-Stop: $network $remote_fs 16180740Sdes# Default-Start: 3 5 17180740Sdes# Default-Stop: 0 1 2 6 18180740Sdes# Description: Start the sshd daemon 19180740Sdes### END INIT INFO 20180740Sdes 21180740SdesSSHD_BIN=/usr/sbin/sshd 22180740Sdestest -x $SSHD_BIN || exit 5 23180740Sdes 24180740SdesSSHD_SYSCONFIG=/etc/sysconfig/ssh 25180740Sdestest -r $SSHD_SYSCONFIG || exit 6 26180740Sdes. $SSHD_SYSCONFIG 27180740Sdes 28180740SdesSSHD_PIDFILE=/var/run/sshd.init.pid 29180740Sdes 30180740Sdes. /etc/rc.status 31180740Sdes 32180740Sdes# Shell functions sourced from /etc/rc.status: 33180740Sdes# rc_check check and set local and overall rc status 34180740Sdes# rc_status check and set local and overall rc status 35180740Sdes# rc_status -v ditto but be verbose in local rc status 36180740Sdes# rc_status -v -r ditto and clear the local rc status 37180740Sdes# rc_failed set local and overall rc status to failed 38180740Sdes# rc_reset clear local rc status (overall remains) 39180740Sdes# rc_exit exit appropriate to overall rc status 40180740Sdes 41180740Sdes# First reset status of this service 42180740Sdesrc_reset 43180740Sdes 44180740Sdescase "$1" in 45180740Sdes start) 46180740Sdes # Generate any missing host keys 47180740Sdes ssh-keygen -A 48180740Sdes echo -n "Starting SSH daemon" 49180740Sdes ## Start daemon with startproc(8). If this fails 50180740Sdes ## the echo return value is set appropriate. 51180740Sdes 52180740Sdes startproc -f -p $SSHD_PIDFILE /usr/sbin/sshd $SSHD_OPTS -o "PidFile=$SSHD_PIDFILE" 53180740Sdes 54180740Sdes # Remember status and be verbose 55180740Sdes rc_status -v 56180740Sdes ;; 57180740Sdes stop) 58180740Sdes echo -n "Shutting down SSH daemon" 59180740Sdes ## Stop daemon with killproc(8) and if this fails 60180740Sdes ## set echo the echo return value. 61180740Sdes 62180740Sdes killproc -p $SSHD_PIDFILE -TERM /usr/sbin/sshd 63180740Sdes 64180740Sdes # Remember status and be verbose 65180740Sdes rc_status -v 66180740Sdes ;; 67180740Sdes try-restart) 68180740Sdes ## Stop the service and if this succeeds (i.e. the 69180740Sdes ## service was running before), start it again. 70180740Sdes $0 status >/dev/null && $0 restart 71180740Sdes 72180740Sdes # Remember status and be quiet 73180740Sdes rc_status 74180740Sdes ;; 75180740Sdes restart) 76180740Sdes ## Stop the service and regardless of whether it was 77180740Sdes ## running or not, start it again. 78180740Sdes $0 stop 79180740Sdes $0 start 80180740Sdes 81180740Sdes # Remember status and be quiet 82180740Sdes rc_status 83180740Sdes ;; 84180740Sdes force-reload|reload) 85180740Sdes ## Signal the daemon to reload its config. Most daemons 86180740Sdes ## do this on signal 1 (SIGHUP). 87180740Sdes 88180740Sdes echo -n "Reload service sshd" 89180740Sdes 90180740Sdes killproc -p $SSHD_PIDFILE -HUP /usr/sbin/sshd 91180740Sdes 92180740Sdes rc_status -v 93180740Sdes 94180740Sdes ;; 95180740Sdes status) 96180740Sdes echo -n "Checking for service sshd " 97180740Sdes ## Check status with checkproc(8), if process is running 98180740Sdes ## checkproc will return with exit status 0. 99180740Sdes 100180740Sdes # Status has a slightly different for the status command: 101180740Sdes # 0 - service running 102180740Sdes # 1 - service dead, but /var/run/ pid file exists 103180740Sdes # 2 - service dead, but /var/lock/ lock file exists 104180740Sdes # 3 - service not running 105180740Sdes 106180740Sdes checkproc -p $SSHD_PIDFILE /usr/sbin/sshd 107180740Sdes 108180740Sdes rc_status -v 109180740Sdes ;; 110180740Sdes probe) 111180740Sdes ## Optional: Probe for the necessity of a reload, 112180740Sdes ## give out the argument which is required for a reload. 113180740Sdes 114180740Sdes test /etc/ssh/sshd_config -nt $SSHD_PIDFILE && echo reload 115180740Sdes ;; 116180740Sdes *) 117180740Sdes echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}" 118180740Sdes exit 1 119180740Sdes ;; 120180740Sdesesac 121180740Sdesrc_exit 122180740Sdes