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
|
Writing System V init scripts for Red Hat Linux
===============================================
All System V init scripts are named /etc/rc.d/init.d/<servicename>
where <servicename> is the name of the service. There must be no
".init" suffix.
Sample Script
=============
#!/bin/bash
#
# /etc/rc.d/init.d/<servicename>
#
# <description of the *service*>
# <any general comments about this init script>
#
# <tags -- see below for tag definitions. *Every line* from the top
# of the file to the end of the tags section must begin with a #
# character. After the tags section, there should be a blank line.
# This keeps normal comments in the rest of the file from being
# mistaken for tags, should they happen to fit the pattern.>
# Source function library.
. /etc/rc.d/init.d/functions
<define any local shell functions used by the code that follows>
case "$1" in
start)
echo -n "Starting <servicename> services: "
<start daemons, perhaps with the daemon function>
touch /var/lock/subsys/<servicename>
;;
stop)
echo -n "Shutting down <servicename> services: "
<stop daemons, perhaps with the killproc function>
rm -f /var/lock/subsys/<servicename>
;;
status)
<report the status of the daemons in free-form format,
perhaps with the status function>
;;
restart)
<restart the daemons, normally with $0 stop; $0 start>
;;
reload)
<cause the service configuration to be reread, either with
kill -HUP or by restarting the daemons, possibly with
$0 stop; $0 start>
;;
probe)
<optional. If it exists, then it should determine whether
or not the service needs to be restarted or reloaded (or
whatever) in order to activate any changes in the configuration
scripts. It should print out a list of commands to give to
$0; see the description under the probe tag below.>
;;
*)
echo "Usage: <servicename> {start|stop|status|reload|restart[|probe]"
exit 1
;;
esac
Notes: the restart and reload functions may be (and commonly are)
combined into one test, vis:
restart|reload)
You are not prohibited from adding other commands; list all commands
which you intend to be used interactively to the usage message.
Functions in /etc/rc.d/init.d/functions
=======================================
daemon [+/-nicelevel] program [arguments] [&]
Starts a daemon, if it is not already running. Does
other useful things like keeping the daemon from dumping
core if it terminates unexpectedly.
killproc program [signal]
Sends a signal to the program; by default it sends a SIGTERM,
and if the process doesn't die, it sends a SIGKILL a few
seconds later.
It also tries to remove the pidfile, if it finds one.
pidofproc program
Tries to find the pid of a program; checking likely pidfiles,
using the pidof program, or even using ps. Used mainly from
within other functions in this file, but also available to
scripts.
status program
Prints status information. Assumes that the program name is
the same as the servicename.
Tags
====
# chkconfig: <startlevellist> <startpriority> <endpriority>
Required. <startlevellist> is a list of levels in which
the service should be started by default. <startpriority>
and <endpriority> are priority numbers. For example:
# chkconfig: 2345 20 80
Read 'man chkconfig' for more information.
# description: <multi-line description of service>
Required. Several lines of description, continued with '\'
characters. The initial comment and following whitespace
on the following lines is ignored.
# description[ln]: <multi-line description of service in the language \
# ln, whatever that is>
Optional. Should be the description translated into the
specified language.
# autoreload: true
Optional. If this line exists, the daemon checks its
configuration files and reloads them automatically when
they change.
# processname:
Optional, multiple entries allowed. For each process name
started by the script, there should be a processname entry.
For example, the samba service starts two daemons:
# processname: smdb
# processname: nmdb
# config:
Optional, multiple entries allowed. For each static config
file used by the daemon, use a single entry. For example:
# config: /etc/httpd/conf/httpd.conf
# config: /etc/httpd/conf/srm.conf
# pidfile:
Optional, multiple entries allowed. Use just like the config
entry, except that it points at pidfiles. It is assumed that
the pidfiles are only updated at process creation time, and
not later. The first line of this file should be the ASCII
representation of the PID; a terminating newline is optional.
Any lines other than the first line are not examined.
# probe: true
Optional, used IN PLACE of autoreload, processname, config,
and pidfile. If it exists, then a proper reload-if-necessary
cycle may be acheived by running these commands:
command=$(/etc/rd.d/init.d/SCRIPT probe)
[ -n "$command" ] && /etc/rc.d/init.d/SCRIPT $command
where SCRIPT is the name of the service's sysv init script.
Scripts that need to do complex processing could, as an
example, return "run /var/tmp/<servicename.probe.$$"
and implement a "run" command which would execute the
named script and then remove it.
Note that the probe command should simply "exit 0" if nothing
needs to be done to bring the service into sync with its
configuration files.
Copyright (c) 1998 Red Hat Software, Inc.
|