Patch from Tim Bielawa <timbielawa@gmail.com> to make init scripts work
[certmaster.git] / init-scripts / certmaster
1 #!/bin/sh
2 #
3 # certmaster certmaster
4 ###################################
5
6 # LSB header
7
8 ### BEGIN INIT INFO
9 # Provides: certmaster
10 # Required-Start: network
11 # Default-Start: 3 4 5
12 # Default-Stop: 0 1 2 6
13 # Short-Description: certificate master for Fedora Unified Network Control 'master server only'
14 # Description: certificate master to sign/manage ca/cert infrastructure
15 ### END INIT INFO
16
17 # chkconfig header
18
19 # chkconfig: - 98 99
20 # description: certificate master to sign/manage ca/cert infrastructure
21 #
22 # processname: /usr/bin/certmaster
23
24 # Sanity checks.
25 [ -x /usr/bin/certmaster ] || exit 0
26
27 SERVICE=certmaster
28 PROCESS=certmaster
29 DAEMON=/usr/bin/certmaster
30 CONFIG_ARGS="--daemon"
31
32 CAStatus()
33 {
34 ps wt? | grep "$DAEMON" 2>&1 > /dev/null
35 if [ "x$?" = "x0" ]; then
36 RVAL=0
37 echo "certmaster is running"
38 else
39 RVAL=3
40 echo "certmaster is not running"
41 fi
42 }
43
44 if [ -f /lib/lsb/init-functions ]; then
45 . /lib/lsb/init-functions
46 alias START_DAEMON=start_daemon
47 alias STATUS=CAStatus
48 alias LOG_SUCCESS=log_success_msg
49 alias LOG_FAILURE=log_failure_msg
50 alias LOG_WARNING=log_warning_msg
51 elif [ -f /etc/init.d/functions ]; then
52 . /etc/init.d/functions
53 alias START_DAEMON=daemon
54 alias STATUS=status
55 alias LOG_SUCCESS=success
56 alias LOG_FAILURE=failure
57 alias LOG_WARNING=passed
58 else
59 echo "Error: your platform is not supported by $0" > /dev/stderr
60 exit 1
61 fi
62
63 RETVAL=0
64
65 start() {
66 if [ -f /etc/debian_version ]; then
67 log_begin_msg "Starting certmaster daemon: "
68 start-stop-daemon --exec $DAEMON --start --quiet -- $CONFIG_ARGS > /dev/null
69 RETVAL=$?
70 log_end_msg $RETVAL
71 return $RETVAL
72 else
73 echo -n $"Starting certmaster daemon: "
74 START_DAEMON $PROCESS $CONFIG_ARGS
75 RETVAL=$?
76 echo
77 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$SERVICE
78 return $RETVAL
79 fi
80 }
81
82 stop() {
83 if [ -f /etc/debian_version ]; then
84 log_daemon_msg "Stopping certmaster daemon" "certmaster"
85 start-stop-daemon --stop --quiet --pidfile /var/run/certmaster.pid --name certmaster
86 RETVAL=$?
87 log_end_msg $RETVAL
88 rm -f /var/run/certmaster.pid
89 else
90 echo -n $"Stopping certmaster daemon: "
91 killproc $PROCESS
92 RETVAL=$?
93 echo
94 if [ $RETVAL -eq 0 ]; then
95 rm -f /var/lock/subsys/$SERVICE
96 rm -f /var/run/$SERVICE.pid
97 fi
98 fi
99 }
100
101 restart() {
102 stop
103 start
104 }
105
106 # See how we were called.
107 case "$1" in
108 start|stop|restart)
109 $1
110 ;;
111 status)
112 STATUS $PROCESS
113 RETVAL=$?
114 ;;
115 condrestart)
116 [ -f /var/lock/subsys/$SERVICE ] && restart || :
117 ;;
118 reload)
119 echo "can't reload configuration, you have to restart it"
120 RETVAL=$?
121 ;;
122 *)
123 echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
124 exit 1
125 ;;
126 esac
127 exit $RETVAL
128