]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - crypto/openssh/opensshd.init.in
Merge bmake-20230414
[FreeBSD/FreeBSD.git] / crypto / openssh / opensshd.init.in
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
6 umask 022
7
8 CAT=@CAT@
9 KILL=@KILL@
10
11 prefix=@prefix@
12 sysconfdir=@sysconfdir@
13 piddir=@piddir@
14
15 SSHD=$prefix/sbin/sshd
16 PIDFILE=$piddir/sshd.pid
17 PidFile=`grep "^PidFile" ${sysconfdir}/sshd_config | tr "=" " " | awk '{print $2}'`
18 [ X$PidFile = X ]  ||  PIDFILE=$PidFile
19 SSH_KEYGEN=$prefix/bin/ssh-keygen
20
21 stop_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
32 start_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
50 case $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     ;;
68 esac