- start pl_sshd after sshd so that it works the first time after an
[pl_sshd.git] / pl_sshd
1 #!/bin/bash
2 #
3 # Init file for PlanetLab OpenSSH server daemon (copied from standard
4 # sshd init file, minor modifications made).
5 #
6 # chkconfig: 2345 56 25
7 # description: PlanetLab OpenSSH server daemon
8 #
9 # processname: sshd
10 # config: /etc/ssh/ssh_host_key
11 # config: /etc/ssh/ssh_host_key.pub
12 # config: /etc/ssh/ssh_random_seed
13 # config: /etc/ssh/sshd_config
14 # pidfile: /var/run/pl_sshd.pid
15
16 # source function library
17 . /etc/rc.d/init.d/functions
18
19 # pull in sysconfig settings
20 [ -f /etc/sysconfig/pl_sshd ] && . /etc/sysconfig/pl_sshd
21
22 RETVAL=0
23 prog="pl_sshd"
24
25 # Some functions to make the below more readable
26 SSHD=/usr/local/sbin/pl_sshd.sh
27 PID_FILE=/var/run/pl_sshd.pid
28
29 do_restart_sanity_check()
30 {
31         $SSHD -t
32         RETVAL=$?
33         if [ ! "$RETVAL" = 0 ]; then
34                 failure $"Configuration file or keys are invalid"
35                 echo
36         fi
37 }
38
39 start()
40 {
41         echo -n $"Starting $prog:"
42         initlog -c "$SSHD $OPTIONS" && success || failure
43         RETVAL=$?
44         [ "$RETVAL" = 0 ] && touch /var/lock/subsys/pl_sshd
45         echo
46 }
47
48 stop()
49 {
50         echo -n $"Stopping $prog:"
51         killproc $prog -TERM
52         RETVAL=$?
53         [ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/pl_sshd
54         echo
55 }
56
57 reload()
58 {
59         echo -n $"Reloading $prog:"
60         killproc $prog -HUP
61         RETVAL=$?
62         echo
63 }
64
65 case "$1" in
66         start)
67                 start
68                 ;;
69         stop)
70                 stop
71                 ;;
72         restart)
73                 stop
74                 start
75                 ;;
76         reload)
77                 reload
78                 ;;
79         condrestart)
80                 if [ -f /var/lock/subsys/pl_sshd ] ; then
81                         do_restart_sanity_check
82                         if [ "$RETVAL" = 0 ] ; then
83                                 stop
84                                 # avoid race
85                                 sleep 3
86                                 start
87                         fi
88                 fi
89                 ;;
90         status)
91                 status pl_sshd
92                 RETVAL=$?
93                 ;;
94         *)
95                 echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
96                 RETVAL=1
97 esac
98 exit $RETVAL