aboutsummaryrefslogtreecommitdiffstats
path: root/meta-networking/recipes-daemons/openhpi/files/openhpi.init
blob: 3a5f4a06aca60e30a227ef51bc1b7d78d8fb7ead (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#! /bin/sh
#
### BEGIN INIT INFO
# Provides:          openhpid
# Required-Start:    $network $remote_fs $syslog
# Required-Stop:     $network $remote_fs $syslog
# Should-Start:      $named
# Should-Stop:       $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start OpenHPI daemon at boot time
# Description:       Enable OpenHPI service which is provided by openhpid.
### END INIT INFO
#
# openhpid.sh    Start/Stop the openhpi daemon.
#
# description: openhpid is standard UNIX program which uses the OpenHPI \
#              APIs and provides a standard internet server to access those \
#              APIs for client programs.
# processname: openhpid
# config: the standard openhpi conf file specified on the command line or the env.
# pidfile: /var/run/openhpid.pid
#
# Author(s):
#	W. David Ashley <dashley@us.ibm.com>
#	Daniel de Araujo <ddearauj@us.ibm.com>

# Source function library.
PATH=/sbin:/bin:/usr/sbin:/usr/bin
prog="OpenHPI"

# If the openhpid executable is not available, we can't do any of this
test -f /usr/sbin/openhpid || exit 0

# Determine whether the lsb package is installed
# If it is, determine which lsb is installed:
# redhat, suse, or standard lsb

if test -f /etc/init.d/functions
then
   lsbtype="rh"
   . /etc/init.d/functions
elif test -f /etc/rc.status
then
   lsbtype="suse"
   . /etc/rc.status
elif test -f /lib/lsb/init-functions
then
   lsbtype="lsb"
   . /lib/lsb/init-functions
elif test -f /etc/gentoo-release
then
   lsbtype="gentoo"
   . /sbin/functions.sh
else
   lsbtype="nolsb"
fi

print_outcome()
{

	case "${lsbtype}" in

		suse)
 			rc_status -v
			;;

		lsb)
			if test "$?" -eq 0
   			then
      			log_success_msg "success"
   			else
				log_failure_msg "failed"
   			fi
  			;;
  
  		gentoo)
  			eend $?
  			;;

		nolsb | rh)
			if test "$?" -eq 0
			then
				echo " ... success"
			fi
			if test "$?" -ne 0
			then
				echo " ... failed"
			fi
			;;
   	esac
}

start() {
	case "${lsbtype}" in

		suse)
			echo -n "Starting $prog: "
			startproc /usr/sbin/openhpid -c /etc/openhpi/openhpi.conf
			RETVAL=$?
			;;
		lsb)
			echo -n "Starting $prog: "
			start_daemon /usr/sbin/openhpid -c /etc/openhpi/openhpi.conf
			RETVAL=$?
			;;
		gentoo | rh)
			echo "Starting $prog: "
			start-stop-daemon --start --quiet --exec /usr/sbin/openhpid -- -c /etc/openhpi/openhpi.conf
			RETVAL=$?
			;;
		nolsb)
			echo -n "Starting $prog: "
			/usr/sbin/openhpid -c /etc/openhpi/openhpi.conf
			RETVAL=$?
			;;

	esac

	print_outcome

}

stop() {
	case "${lsbtype}" in

		lsb | suse)
			echo -n "Stopping $prog: "
			killproc /usr/sbin/openhpid
			RETVAL=$?
			;;

		gentoo)
			echo "Stopping $prog: "
			start-stop-daemon --stop --quiet --exec /usr/sbin/openhpid
			RETVAL=$?
			;;

		nolsb | rh)
			echo -n "Stopping $prog: "
			if test -f /var/run/openhpid.pid && test "`cat /var/run/openhpid.pid`" != ""
         		then
            			kill "`cat /var/run/openhpid.pid`"
				RETVAL=$?
			else
				RETVAL=0
			fi
			;;

	esac

	print_outcome

	if test "$RETVAL" -eq 0 && test -f /var/run/openhpid.pid
	then
		rm -f /var/lock/openhpid
		rm -f /var/run/openhpid.pid
	fi

}

dstatus() {
	echo "Checking for $prog daemon: "

	case "${lsbtype}" in

		suse)
			checkproc /usr/sbin/openhpid
			rc_status -v
			;;
		lsb)
			pid="`pidofproc /usr/sbin/openhpid`"
         		if test "${pid}" != ""
			then
				log_success_msg "$prog is running"
			else
				log_success_msg "$prog is not running"
			fi
			;;
		gentoo | nolsb | rh)
			if test -f /var/run/openhpid.pid &&
				test "`cat /var/run/openhpid.pid`" != "" &&
				kill -s 0 "`cat /var/run/openhpid.pid`"
			then
				echo "$prog is running"
			else
				echo "$prog is not running"
			fi

			;;

	esac



}

restart() {
  	stop
	start
}

force_reload() {
	# We don't currently support a reload, but can do a restart
	stop
	start
}

# See how we were called.

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
  	restart
	;;
  status)
  	dstatus
	;;
  force-reload)
  	force_reload
	;;
  *)
	echo "Usage: $0 {start|stop|restart|status|force-reload}"
	exit 1
esac