xref: /freebsd/crypto/openssh/opensshd.init.in (revision 25ecdc7d52770caf1c9b44b5ec11f468f6b636f3)
1#!@STARTUP_SCRIPT_SHELL@
2# Donated code that was put under PD license.
3#
4# Stripped PRNGd out of it for the time being.
5
6umask 022
7
8CAT=@CAT@
9KILL=@KILL@
10
11prefix=@prefix@
12sysconfdir=@sysconfdir@
13piddir=@piddir@
14
15SSHD=$prefix/sbin/sshd
16PIDFILE=$piddir/sshd.pid
17PidFile=`grep "^PidFile" ${sysconfdir}/sshd_config | tr "=" " " | awk '{print $2}'`
18[ X$PidFile = X ]  ||  PIDFILE=$PidFile
19SSH_KEYGEN=$prefix/bin/ssh-keygen
20HOST_KEY_DSA=$sysconfdir/ssh_host_dsa_key
21HOST_KEY_RSA=$sysconfdir/ssh_host_rsa_key
22@COMMENT_OUT_ECC@HOST_KEY_ECDSA=$sysconfdir/ssh_host_ecdsa_key
23HOST_KEY_ED25519=$sysconfdir/ssh_host_ed25519_key
24
25
26checkkeys() {
27    if [ ! -f $HOST_KEY_DSA ]; then
28	${SSH_KEYGEN} -t dsa -f ${HOST_KEY_DSA} -N ""
29    fi
30    if [ ! -f $HOST_KEY_RSA ]; then
31	${SSH_KEYGEN} -t rsa -f ${HOST_KEY_RSA} -N ""
32    fi
33@COMMENT_OUT_ECC@    if [ ! -f $HOST_KEY_ECDSA ]; then
34@COMMENT_OUT_ECC@	${SSH_KEYGEN} -t ecdsa -f ${HOST_KEY_ECDSA} -N ""
35@COMMENT_OUT_ECC@    fi
36    if [ ! -f $HOST_KEY_ED25519 ]; then
37	${SSH_KEYGEN} -t ed25519 -f ${HOST_KEY_ED25519} -N ""
38    fi
39}
40
41stop_service() {
42    if [  -r $PIDFILE  -a  ! -z ${PIDFILE}  ]; then
43	PID=`${CAT} ${PIDFILE}`
44    fi
45    if [  ${PID:=0} -gt 1 -a  ! "X$PID" = "X "  ]; then
46	${KILL} ${PID}
47    else
48	echo "Unable to read PID file"
49    fi
50}
51
52start_service() {
53    # XXX We really should check if the service is already going, but
54    # XXX we will opt out at this time. - Bal
55
56    # Check to see if we have keys that need to be made
57    checkkeys
58
59    # Start SSHD
60    echo "starting $SSHD... \c"         ; $SSHD
61
62    sshd_rc=$?
63    if [ $sshd_rc -ne 0 ]; then
64	echo "$0: Error ${sshd_rc} starting ${SSHD}... bailing."
65	exit $sshd_rc
66    fi
67    echo done.
68}
69
70case $1 in
71
72'start')
73    start_service
74    ;;
75
76'stop')
77    stop_service
78    ;;
79
80'restart')
81    stop_service
82    start_service
83    ;;
84
85*)
86    echo "$0:  usage:  $0 {start|stop|restart}"
87    ;;
88esac
89