openssh/contrib/redhat/sshd.init

103 lines
1.8 KiB
Plaintext
Raw Normal View History

1999-10-27 03:42:43 +00:00
#!/bin/bash
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
#
# 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
RETVAL=0
# Some functions to make the below more readable
KEYGEN=/usr/bin/ssh-keygen
RSA_KEY=/etc/ssh/ssh_host_key
DSA_KEY=/etc/ssh/ssh_host_dsa_key
PID_FILE=/var/run/sshd.pid
do_rsa_keygen() {
if $KEYGEN -R && ! test -f $RSA_KEY ; then
echo -n "Generating SSH RSA host key: "
if $KEYGEN -q -b 1024 -f $RSA_KEY -C '' -N '' >&/dev/null; then
success "RSA key generation"
echo
else
failure "RSA key generation"
echo
exit 1
fi
fi
}
do_dsa_keygen() {
if ! test -f $DSA_KEY ; then
echo -n "Generating SSH DSA host key: "
if $KEYGEN -q -d -b 1024 -f $DSA_KEY -C '' -N '' >&/dev/null; then
success "DSA key generation"
echo
else
failure "DSA key generation"
echo
exit 1
fi
fi
}
case "$1" in
start)
# Create keys if necessary
do_rsa_keygen;
do_dsa_keygen;
echo -n "Starting sshd: "
if [ ! -f $PID_FILE ] ; then
2000-09-03 08:14:58 +00:00
sshd
RETVAL=$?
2000-09-03 08:14:58 +00:00
if [ "$RETVAL" = "0" ] ; then
success "sshd startup"
touch /var/lock/subsys/sshd
else
failure "sshd startup"
fi
fi
echo
;;
stop)
echo -n "Shutting down sshd: "
if [ -f $PID_FILE ] ; then
killproc sshd
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sshd
fi
echo
;;
restart)
$0 stop
$0 start
RETVAL=$?
;;
condrestart)
if [ -f /var/lock/subsys/sshd ] ; then
$0 stop
$0 start
RETVAL=$?
fi
;;
status)
status sshd
RETVAL=$?
;;
*)
echo "Usage: sshd {start|stop|restart|status|condrestart}"
exit 1
;;
1999-10-27 03:42:43 +00:00
esac
exit $RETVAL