blob: 3a5f4a06aca60e30a227ef51bc1b7d78d8fb7ead [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001#! /bin/sh
2#
3### BEGIN INIT INFO
4# Provides: openhpid
5# Required-Start: $network $remote_fs $syslog
6# Required-Stop: $network $remote_fs $syslog
7# Should-Start: $named
8# Should-Stop: $named
9# Default-Start: 2 3 4 5
10# Default-Stop: 0 1 6
11# Short-Description: Start OpenHPI daemon at boot time
12# Description: Enable OpenHPI service which is provided by openhpid.
13### END INIT INFO
14#
15# openhpid.sh Start/Stop the openhpi daemon.
16#
17# description: openhpid is standard UNIX program which uses the OpenHPI \
18# APIs and provides a standard internet server to access those \
19# APIs for client programs.
20# processname: openhpid
21# config: the standard openhpi conf file specified on the command line or the env.
22# pidfile: /var/run/openhpid.pid
23#
24# Author(s):
25# W. David Ashley <dashley@us.ibm.com>
26# Daniel de Araujo <ddearauj@us.ibm.com>
27
28# Source function library.
29PATH=/sbin:/bin:/usr/sbin:/usr/bin
30prog="OpenHPI"
31
32# If the openhpid executable is not available, we can't do any of this
33test -f /usr/sbin/openhpid || exit 0
34
35# Determine whether the lsb package is installed
36# If it is, determine which lsb is installed:
37# redhat, suse, or standard lsb
38
39if test -f /etc/init.d/functions
40then
41 lsbtype="rh"
42 . /etc/init.d/functions
43elif test -f /etc/rc.status
44then
45 lsbtype="suse"
46 . /etc/rc.status
47elif test -f /lib/lsb/init-functions
48then
49 lsbtype="lsb"
50 . /lib/lsb/init-functions
51elif test -f /etc/gentoo-release
52then
53 lsbtype="gentoo"
54 . /sbin/functions.sh
55else
56 lsbtype="nolsb"
57fi
58
59print_outcome()
60{
61
62 case "${lsbtype}" in
63
64 suse)
65 rc_status -v
66 ;;
67
68 lsb)
69 if test "$?" -eq 0
70 then
71 log_success_msg "success"
72 else
73 log_failure_msg "failed"
74 fi
75 ;;
76
77 gentoo)
78 eend $?
79 ;;
80
81 nolsb | rh)
82 if test "$?" -eq 0
83 then
84 echo " ... success"
85 fi
86 if test "$?" -ne 0
87 then
88 echo " ... failed"
89 fi
90 ;;
91 esac
92}
93
94start() {
95 case "${lsbtype}" in
96
97 suse)
98 echo -n "Starting $prog: "
99 startproc /usr/sbin/openhpid -c /etc/openhpi/openhpi.conf
100 RETVAL=$?
101 ;;
102 lsb)
103 echo -n "Starting $prog: "
104 start_daemon /usr/sbin/openhpid -c /etc/openhpi/openhpi.conf
105 RETVAL=$?
106 ;;
107 gentoo | rh)
108 echo "Starting $prog: "
109 start-stop-daemon --start --quiet --exec /usr/sbin/openhpid -- -c /etc/openhpi/openhpi.conf
110 RETVAL=$?
111 ;;
112 nolsb)
113 echo -n "Starting $prog: "
114 /usr/sbin/openhpid -c /etc/openhpi/openhpi.conf
115 RETVAL=$?
116 ;;
117
118 esac
119
120 print_outcome
121
122}
123
124stop() {
125 case "${lsbtype}" in
126
127 lsb | suse)
128 echo -n "Stopping $prog: "
129 killproc /usr/sbin/openhpid
130 RETVAL=$?
131 ;;
132
133 gentoo)
134 echo "Stopping $prog: "
135 start-stop-daemon --stop --quiet --exec /usr/sbin/openhpid
136 RETVAL=$?
137 ;;
138
139 nolsb | rh)
140 echo -n "Stopping $prog: "
141 if test -f /var/run/openhpid.pid && test "`cat /var/run/openhpid.pid`" != ""
142 then
143 kill "`cat /var/run/openhpid.pid`"
144 RETVAL=$?
145 else
146 RETVAL=0
147 fi
148 ;;
149
150 esac
151
152 print_outcome
153
154 if test "$RETVAL" -eq 0 && test -f /var/run/openhpid.pid
155 then
156 rm -f /var/lock/openhpid
157 rm -f /var/run/openhpid.pid
158 fi
159
160}
161
162dstatus() {
163 echo "Checking for $prog daemon: "
164
165 case "${lsbtype}" in
166
167 suse)
168 checkproc /usr/sbin/openhpid
169 rc_status -v
170 ;;
171 lsb)
172 pid="`pidofproc /usr/sbin/openhpid`"
173 if test "${pid}" != ""
174 then
175 log_success_msg "$prog is running"
176 else
177 log_success_msg "$prog is not running"
178 fi
179 ;;
180 gentoo | nolsb | rh)
181 if test -f /var/run/openhpid.pid &&
182 test "`cat /var/run/openhpid.pid`" != "" &&
183 kill -s 0 "`cat /var/run/openhpid.pid`"
184 then
185 echo "$prog is running"
186 else
187 echo "$prog is not running"
188 fi
189
190 ;;
191
192 esac
193
194
195
196}
197
198restart() {
199 stop
200 start
201}
202
203force_reload() {
204 # We don't currently support a reload, but can do a restart
205 stop
206 start
207}
208
209# See how we were called.
210
211case "$1" in
212 start)
213 start
214 ;;
215 stop)
216 stop
217 ;;
218 restart)
219 restart
220 ;;
221 status)
222 dstatus
223 ;;
224 force-reload)
225 force_reload
226 ;;
227 *)
228 echo "Usage: $0 {start|stop|restart|status|force-reload}"
229 exit 1
230esac