]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - crypto/openssh/contrib/redhat/sshd.init
Upgrade to OpenSSH 7.7p1.
[FreeBSD/FreeBSD.git] / crypto / openssh / contrib / redhat / sshd.init
1 #!/bin/bash
2 #
3 # Init file for OpenSSH server daemon
4 #
5 # chkconfig: 2345 55 25
6 # description: OpenSSH server daemon
7 #
8 # processname: sshd
9 # config: /etc/ssh/ssh_host_key
10 # config: /etc/ssh/ssh_host_key.pub
11 # config: /etc/ssh/ssh_random_seed
12 # config: /etc/ssh/sshd_config
13 # pidfile: /var/run/sshd.pid
14
15 # source function library
16 . /etc/rc.d/init.d/functions
17
18 # pull in sysconfig settings
19 [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
20
21 RETVAL=0
22 prog="sshd"
23
24 # Some functions to make the below more readable
25 SSHD=/usr/sbin/sshd
26 PID_FILE=/var/run/sshd.pid
27
28 do_restart_sanity_check()
29 {
30         $SSHD -t
31         RETVAL=$?
32         if [ $RETVAL -ne 0 ]; then
33                 failure $"Configuration file or keys are invalid"
34                 echo
35         fi
36 }
37
38 start()
39 {
40         # Create keys if necessary
41         /usr/bin/ssh-keygen -A
42         if [ -x /sbin/restorecon ]; then
43                 /sbin/restorecon /etc/ssh/ssh_host_rsa_key.pub
44                 /sbin/restorecon /etc/ssh/ssh_host_dsa_key.pub
45                 /sbin/restorecon /etc/ssh/ssh_host_ecdsa_key.pub
46         fi
47
48         echo -n $"Starting $prog:"
49         $SSHD $OPTIONS && success || failure
50         RETVAL=$?
51         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sshd
52         echo
53 }
54
55 stop()
56 {
57         echo -n $"Stopping $prog:"
58         killproc $SSHD -TERM
59         RETVAL=$?
60         [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sshd
61         echo
62 }
63
64 reload()
65 {
66         echo -n $"Reloading $prog:"
67         killproc $SSHD -HUP
68         RETVAL=$?
69         echo
70 }
71
72 case "$1" in
73         start)
74                 start
75                 ;;
76         stop)
77                 stop
78                 ;;
79         restart)
80                 stop
81                 start
82                 ;;
83         reload)
84                 reload
85                 ;;
86         condrestart)
87                 if [ -f /var/lock/subsys/sshd ] ; then
88                         do_restart_sanity_check
89                         if [ $RETVAL -eq 0 ] ; then
90                                 stop
91                                 # avoid race
92                                 sleep 3
93                                 start
94                         fi
95                 fi
96                 ;;
97         status)
98                 status $SSHD
99                 RETVAL=$?
100                 ;;
101         *)
102                 echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
103                 RETVAL=1
104 esac
105 exit $RETVAL