b5a16a575edc441d6a07a8c94e23506dd985f669
[public/netxms.git] / contrib / startup / suse / nxhttpd.in
1 #!/bin/sh
2 #
3 # SUSE system startup script for NetXMS Agent
4 # Copyright (c) 2007 Victor Kirhenshtein
5 # Based on:
6 # Template SUSE system startup script for example service/daemon FOO
7 # Copyright (C) 1995--2005 Kurt Garloff, SUSE / Novell Inc.
8 #
9 # This library is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU Lesser General Public License as published by
11 # the Free Software Foundation; either version 2.1 of the License, or (at
12 # your option) any later version.
13 #
14 # This library is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
22 # USA.
23 #
24 # Note: This template uses functions rc_XXX defined in /etc/rc.status on
25 # UnitedLinux/SUSE/Novell based Linux distributions. If you want to base your
26 # script on this template and ensure that it works on non UL based LSB
27 # compliant Linux distributions, you either have to provide the rc.status
28 # functions from UL or change the script to work without them.
29 # See skeleton.compat for a template that works with other distros as well.
30 #
31 ### BEGIN INIT INFO
32 # Provides: nxhttpd
33 # Required-Start: $syslog $remote_fs
34 # Should-Start: $time
35 # Required-Stop: $syslog $remote_fs
36 # Should-Stop: $time
37 # Default-Start: 3 5
38 # Default-Stop: 0 1 2 6
39 # Short-Description: NetXMS HTTP Server
40 # Description: Start NetXMS HTTP Server
41 ### END INIT INFO
42 #
43 # Any extensions to the keywords given above should be preceeded by
44 # X-VendorTag- (X-UnitedLinux- X-SuSE- for us) according to LSB.
45 #
46 # Notes on Required-Start/Should-Start:
47 # * There are two different issues that are solved by Required-Start
48 # and Should-Start
49 # (a) Hard dependencies: This is used by the runlevel editor to determine
50 # which services absolutely need to be started to make the start of
51 # this service make sense. Example: nfsserver should have
52 # Required-Start: $portmap
53 # Also, required services are started before the dependent ones.
54 # The runlevel editor will warn about such missing hard dependencies
55 # and suggest enabling. During system startup, you may expect an error,
56 # if the dependency is not fulfilled.
57 # (b) Specifying the init script ordering, not real (hard) dependencies.
58 # This is needed by insserv to determine which service should be
59 # started first (and at a later stage what services can be started
60 # in parallel). The tag Should-Start: is used for this.
61 # It tells, that if a service is available, it should be started
62 # before. If not, never mind.
63 # * When specifying hard dependencies or ordering requirements, you can
64 # use names of services (contents of their Provides: section)
65 # or pseudo names starting with a $. The following ones are available
66 # according to LSB (1.1):
67 # $local_fs all local file systems are mounted
68 # (most services should need this!)
69 # $remote_fs all remote file systems are mounted
70 # (note that /usr may be remote, so
71 # many services should Require this!)
72 # $syslog system logging facility up
73 # $network low level networking (eth card, ...)
74 # $named hostname resolution available
75 # $netdaemons all network daemons are running
76 # The $netdaemons pseudo service has been removed in LSB 1.2.
77 # For now, we still offer it for backward compatibility.
78 # These are new (LSB 1.2):
79 # $time the system time has been set correctly
80 # $portmap SunRPC portmapping service available
81 # UnitedLinux extensions:
82 # $ALL indicates that a script should be inserted
83 # at the end
84 # * The services specified in the stop tags
85 # (Required-Stop/Should-Stop)
86 # specify which services need to be still running when this service
87 # is shut down. Often the entries there are just copies or a subset
88 # from the respective start tag.
89 # * Should-Start/Stop are now part of LSB as of 2.0,
90 # formerly SUSE/Unitedlinux used X-UnitedLinux-Should-Start/-Stop.
91 # insserv does support both variants.
92 # * X-UnitedLinux-Default-Enabled: yes/no is used at installation time
93 # (%fillup_and_insserv macro in %post of many RPMs) to specify whether
94 # a startup script should default to be enabled after installation.
95 # It's not used by insserv.
96 #
97 # Note on runlevels:
98 # 0 - halt/poweroff 6 - reboot
99 # 1 - single user 2 - multiuser without network exported
100 # 3 - multiuser w/ network (text mode) 5 - multiuser w/ network and X11 (xdm)
101 #
102 # Note on script names:
103 # http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/scrptnames.html
104 # A registry has been set up to manage the init script namespace.
105 # http://www.lanana.org/
106 # Please use the names already registered or register one or use a
107 # vendor prefix.
108
109 NETXMS_BINDIR="~BINDIR~"
110 NETXMS_LIBDIR="~LIBDIR~"
111
112 # Default command line options
113 NXHTTPD_OPTIONS="-d"
114
115 # Check for missing binaries (stale symlinks should not happen)
116 # Note: Special treatment of stop for LSB conformance
117 NXHTTPD_BIN=$NETXMS_BINDIR/nxhttpd
118 test -x $NXHTTPD_BIN || { echo "$NXHTTPD_BIN not installed";
119 if [ "$1" = "stop" ]; then exit 0;
120 else exit 5; fi; }
121
122 # Check for existence of needed config file and read it
123 NXHTTPD_CONFIG=/etc/sysconfig/nxhttpd
124 test -r $NXHTTPD_CONFIG
125 if [ $? == 0 ]; then
126 . $NXHTTPD_CONFIG
127 fi
128
129 # Source LSB init functions
130 # providing start_daemon, killproc, pidofproc,
131 # log_success_msg, log_failure_msg and log_warning_msg.
132 # This is currently not used by UnitedLinux based distributions and
133 # not needed for init scripts for UnitedLinux only. If it is used,
134 # the functions from rc.status should not be sourced or used.
135 #. /lib/lsb/init-functions
136
137 # Shell functions sourced from /etc/rc.status:
138 # rc_check check and set local and overall rc status
139 # rc_status check and set local and overall rc status
140 # rc_status -v be verbose in local rc status and clear it afterwards
141 # rc_status -v -r ditto and clear both the local and overall rc status
142 # rc_status -s display "skipped" and exit with status 3
143 # rc_status -u display "unused" and exit with status 3
144 # rc_failed set local and overall rc status to failed
145 # rc_failed <num> set local and overall rc status to <num>
146 # rc_reset clear both the local and overall rc status
147 # rc_exit exit appropriate to overall rc status
148 # rc_active checks whether a service is activated by symlinks
149 . /etc/rc.status
150
151 # Reset status of this service
152 rc_reset
153
154 # Return values acc. to LSB for all commands but status:
155 # 0 - success
156 # 1 - generic or unspecified error
157 # 2 - invalid or excess argument(s)
158 # 3 - unimplemented feature (e.g. "reload")
159 # 4 - user had insufficient privileges
160 # 5 - program is not installed
161 # 6 - program is not configured
162 # 7 - program is not running
163 # 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
164 #
165 # Note that starting an already running service, stopping
166 # or restarting a not-running service as well as the restart
167 # with force-reload (in case signaling is not supported) are
168 # considered a success.
169
170 case "$1" in
171 start)
172 echo -n "Starting NetXMS HTTP server "
173 ## Start daemon with startproc(8). If this fails
174 ## the return value is set appropriately by startproc.
175 /sbin/startproc $NXHTTPD_BIN $NXHTTPD_OPTIONS
176
177 # Remember status and be verbose
178 rc_status -v
179 ;;
180 stop)
181 echo -n "Shutting down NetXMS HTTP server "
182 ## Stop daemon with killproc(8) and if this fails
183 ## killproc sets the return value according to LSB.
184
185 /sbin/killproc -TERM $NXHTTPD_BIN
186
187 # Remember status and be verbose
188 rc_status -v
189 ;;
190 try-restart|condrestart)
191 ## Do a restart only if the service was active before.
192 ## Note: try-restart is now part of LSB (as of 1.9).
193 ## RH has a similar command named condrestart.
194 if test "$1" = "condrestart"; then
195 echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
196 fi
197 $0 status
198 if test $? = 0; then
199 $0 restart
200 else
201 rc_reset # Not running is not a failure.
202 fi
203 # Remember status and be quiet
204 rc_status
205 ;;
206 restart)
207 ## Stop the service and regardless of whether it was
208 ## running or not, start it again.
209 $0 stop
210 $0 start
211
212 # Remember status and be quiet
213 rc_status
214 ;;
215 force-reload)
216 ## Signal the daemon to reload its config. Most daemons
217 ## do this on signal 1 (SIGHUP).
218 ## If it does not support it, restart the service if it
219 ## is running.
220
221 $0 try-restart
222 rc_status
223 ;;
224 reload)
225 ## Like force-reload, but if daemon does not support
226 ## signaling, do nothing (!)
227
228 ## Otherwise if it does not support reload:
229 rc_failed 3
230 rc_status -v
231 ;;
232 status)
233 echo -n "Checking for service NetXMS HTTP server "
234 ## Check status with checkproc(8), if process is running
235 ## checkproc will return with exit status 0.
236
237 # Return value is slightly different for the status command:
238 # 0 - service up and running
239 # 1 - service dead, but /var/run/ pid file exists
240 # 2 - service dead, but /var/lock/ lock file exists
241 # 3 - service not running (unused)
242 # 4 - service status unknown :-(
243 # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
244
245 # NOTE: checkproc returns LSB compliant status values.
246 /sbin/checkproc $NXHTTPD_BIN
247 # NOTE: rc_status knows that we called this init script with
248 # "status" option and adapts its messages accordingly.
249 rc_status -v
250 ;;
251 probe)
252 ## Optional: Probe for the necessity of a reload, print out the
253 ## argument to this init script which is required for a reload.
254 ## Note: probe is not (yet) part of LSB (as of 1.9)
255
256 test /etc/nxhttpd.conf -nt /var/run/nxhttpd.pid && echo reload
257 ;;
258 *)
259 echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
260 exit 1
261 ;;
262 esac
263 rc_exit