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