xref: /freebsd/crypto/openssh/opensshd.init.in (revision 43a5ec4eb41567cc92586503212743d89686d78f)
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
20
21stop_service() {
22    if [  -r $PIDFILE  -a  ! -z ${PIDFILE}  ]; then
23	PID=`${CAT} ${PIDFILE}`
24    fi
25    if [  ${PID:=0} -gt 1 -a  ! "X$PID" = "X "  ]; then
26	${KILL} ${PID}
27    else
28	echo "Unable to read PID file"
29    fi
30}
31
32start_service() {
33    # XXX We really should check if the service is already going, but
34    # XXX we will opt out at this time. - Bal
35
36    # Check to see if we have keys that need to be made
37    ${SSH_KEYGEN} -A
38
39    # Start SSHD
40    echo "starting $SSHD... \c"         ; $SSHD
41
42    sshd_rc=$?
43    if [ $sshd_rc -ne 0 ]; then
44	echo "$0: Error ${sshd_rc} starting ${SSHD}... bailing."
45	exit $sshd_rc
46    fi
47    echo done.
48}
49
50case $1 in
51
52'start')
53    start_service
54    ;;
55
56'stop')
57    stop_service
58    ;;
59
60'restart')
61    stop_service
62    start_service
63    ;;
64
65*)
66    echo "$0:  usage:  $0 {start|stop|restart}"
67    ;;
68esac
69