1999-10-27 03:42:43 +00:00
|
|
|
#!/bin/bash
|
2002-05-10 02:19:23 +00:00
|
|
|
#
|
1999-10-28 04:03:14 +00:00
|
|
|
# Init file for OpenSSH server daemon
|
1999-10-27 03:42:43 +00:00
|
|
|
#
|
|
|
|
# chkconfig: 2345 55 25
|
|
|
|
# description: OpenSSH server daemon
|
|
|
|
#
|
1999-10-28 23:18:29 +00:00
|
|
|
# processname: sshd
|
|
|
|
# config: /etc/ssh/ssh_host_key
|
|
|
|
# config: /etc/ssh/ssh_host_key.pub
|
|
|
|
# config: /etc/ssh/ssh_random_seed
|
|
|
|
# config: /etc/ssh/sshd_config
|
|
|
|
# pidfile: /var/run/sshd.pid
|
1999-10-27 03:42:43 +00:00
|
|
|
|
|
|
|
# source function library
|
|
|
|
. /etc/rc.d/init.d/functions
|
|
|
|
|
2002-05-10 02:19:23 +00:00
|
|
|
# pull in sysconfig settings
|
2001-04-27 00:46:17 +00:00
|
|
|
[ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
|
|
|
|
|
1999-10-27 03:42:43 +00:00
|
|
|
RETVAL=0
|
2002-05-10 02:19:23 +00:00
|
|
|
prog="sshd"
|
1999-10-27 03:42:43 +00:00
|
|
|
|
2000-08-08 06:53:28 +00:00
|
|
|
# Some functions to make the below more readable
|
2002-05-10 02:19:23 +00:00
|
|
|
SSHD=/usr/sbin/sshd
|
2000-08-08 06:53:28 +00:00
|
|
|
PID_FILE=/var/run/sshd.pid
|
2002-05-10 02:19:23 +00:00
|
|
|
|
|
|
|
do_restart_sanity_check()
|
|
|
|
{
|
|
|
|
$SSHD -t
|
2001-09-15 11:03:10 +00:00
|
|
|
RETVAL=$?
|
|
|
|
if [ ! "$RETVAL" = 0 ]; then
|
2002-05-10 02:19:23 +00:00
|
|
|
failure $"Configuration file or keys are invalid"
|
2001-09-15 11:03:10 +00:00
|
|
|
echo
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2002-05-10 02:19:23 +00:00
|
|
|
start()
|
|
|
|
{
|
|
|
|
# Create keys if necessary
|
2011-08-12 01:02:35 +00:00
|
|
|
/usr/bin/ssh-keygen -A
|
|
|
|
if [ -x /sbin/restorecon ]; then
|
2011-09-06 23:15:02 +00:00
|
|
|
/sbin/restorecon /etc/ssh/ssh_host_key.pub
|
|
|
|
/sbin/restorecon /etc/ssh/ssh_host_rsa_key.pub
|
|
|
|
/sbin/restorecon /etc/ssh/ssh_host_dsa_key.pub
|
|
|
|
/sbin/restorecon /etc/ssh/ssh_host_ecdsa_key.pub
|
2011-08-12 01:02:35 +00:00
|
|
|
fi
|
2002-05-10 02:19:23 +00:00
|
|
|
|
|
|
|
echo -n $"Starting $prog:"
|
2010-08-27 00:12:54 +00:00
|
|
|
$SSHD $OPTIONS && success || failure
|
2002-05-10 02:19:23 +00:00
|
|
|
RETVAL=$?
|
|
|
|
[ "$RETVAL" = 0 ] && touch /var/lock/subsys/sshd
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
stop()
|
|
|
|
{
|
|
|
|
echo -n $"Stopping $prog:"
|
|
|
|
killproc $SSHD -TERM
|
|
|
|
RETVAL=$?
|
|
|
|
[ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/sshd
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
reload()
|
|
|
|
{
|
|
|
|
echo -n $"Reloading $prog:"
|
|
|
|
killproc $SSHD -HUP
|
|
|
|
RETVAL=$?
|
|
|
|
echo
|
|
|
|
}
|
2000-08-08 06:53:28 +00:00
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
2002-05-10 02:19:23 +00:00
|
|
|
start
|
2000-08-08 06:53:28 +00:00
|
|
|
;;
|
|
|
|
stop)
|
2002-05-10 02:19:23 +00:00
|
|
|
stop
|
2000-08-08 06:53:28 +00:00
|
|
|
;;
|
|
|
|
restart)
|
2002-05-10 02:19:23 +00:00
|
|
|
stop
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
reload)
|
|
|
|
reload
|
2000-08-08 06:53:28 +00:00
|
|
|
;;
|
2000-10-16 01:25:17 +00:00
|
|
|
condrestart)
|
|
|
|
if [ -f /var/lock/subsys/sshd ] ; then
|
2001-09-15 11:03:10 +00:00
|
|
|
do_restart_sanity_check
|
2002-05-10 02:19:23 +00:00
|
|
|
if [ "$RETVAL" = 0 ] ; then
|
|
|
|
stop
|
|
|
|
# avoid race
|
|
|
|
sleep 3
|
|
|
|
start
|
|
|
|
fi
|
2000-10-16 01:25:17 +00:00
|
|
|
fi
|
|
|
|
;;
|
2000-08-08 06:53:28 +00:00
|
|
|
status)
|
2002-05-10 02:19:23 +00:00
|
|
|
status $SSHD
|
2000-08-08 06:53:28 +00:00
|
|
|
RETVAL=$?
|
|
|
|
;;
|
|
|
|
*)
|
2002-05-10 02:19:23 +00:00
|
|
|
echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
|
|
|
|
RETVAL=1
|
1999-10-27 03:42:43 +00:00
|
|
|
esac
|
|
|
|
exit $RETVAL
|