1 Writing System V init scripts for TLD Linux
2 ===============================================
4 All System V init scripts are named /etc/rc.d/init.d/<servicename>
5 where <servicename> is the name of the service. There must be no
14 # /etc/rc.d/init.d/<servicename>
16 # <description of the *service*>
17 # <any general comments about this init script>
19 # <tags -- see below for tag definitions. *Every line* from the top
20 # of the file to the end of the tags section must begin with a #
21 # character. After the tags section, there should be a blank line.
22 # This keeps normal comments in the rest of the file from being
23 # mistaken for tags, should they happen to fit the pattern.>
25 # Source function library.
26 . /etc/rc.d/init.d/functions
28 # Running service -- nice level.
29 if [ -f /etc/sysconfig/<service> ]; then
30 . /etc/sysconfig/<service>
33 <define any local shell functions used by the code that follows>
37 show Starting <servicename> services
38 <start daemons, perhaps with the daemon function>
39 touch /var/lock/subsys/<servicename>
42 show Shutting down <servicename> services
43 <stop daemons, perhaps with the killproc function>
44 rm -f /var/lock/subsys/<servicename>
47 <report the status of the daemons in free-form format,
48 perhaps with the status function>
51 <restart the daemons, normally with $0 stop; $0 start>
54 <cause the service configuration to be reread, either with
55 kill -HUP or by restarting the daemons, possibly with
59 <optional. If it exists, then it should determine whether
60 or not the service needs to be restarted or reloaded (or
61 whatever) in order to activate any changes in the configuration
62 scripts. It should print out a list of commands to give to
63 $0; see the description under the probe tag below.>
66 echo "Usage: $0 {start|stop|status|reload|restart[|probe]"
72 Notes: the restart and reload functions may be (and commonly are)
73 combined into one test, vis:
75 You are not prohibited from adding other commands; list all commands
76 which you intend to be used interactively to the usage message.
80 Functions in /etc/rc.d/init.d/functions
81 =======================================
83 daemon [+/-nicelevel] program [arguments] [&]
85 Obsoletes starts a daemon, if it is not already running.
86 Does other useful things like keeping the daemon from
87 dumping core if it terminates unexpectedly.
89 killproc program [signal]
91 Sends a signal to the program; by default it sends a SIGTERM,
92 and if the process doesn't die, it sends a SIGKILL a few
95 It also tries to remove the pidfile, if it finds one.
99 Tries to find the pid of a program; checking likely pidfiles,
100 using the pidof program, or even using ps. Used mainly from
101 within other functions in this file, but also available to
106 Prints status information. Assumes that the program name is
107 the same as the servicename.
113 # chkconfig: <startlevellist> <startpriority> <endpriority>
115 Required. <startlevellist> is a list of levels in which
116 the service should be started by default. <startpriority>
117 and <endpriority> are priority numbers. For example:
118 # chkconfig: 2345 20 80
119 Read 'man chkconfig' for more information.
121 Unless there is a VERY GOOD, EXPLICIT reason to the
122 contrary, the <endpriority> should be equal to
123 100 - <startpriority>
125 # description: <multi-line description of service>
127 Required. Several lines of description, continued with '\'
128 characters. The initial comment and following whitespace
129 on the following lines is ignored.
131 # description[ln]: <multi-line description of service in the language \
132 # ln, whatever that is>
134 Optional. Should be the description translated into the
139 Optional, multiple entries allowed. For each process name
140 started by the script, there should be a processname entry.
141 For example, the samba service starts two daemons:
147 Optional, multiple entries allowed. For each static config
148 file used by the daemon, use a single entry. For example:
149 # config: /etc/httpd/httpd.conf
150 # config: /etc/httpd/srm.conf
152 Optionally, if the server will automatically reload the config
153 file if it is changed, you can append the word "autoreload" to
155 # config: /etc/foobar.conf autoreload
159 Optional, multiple entries allowed. Use just like the config
160 entry, except that it points at pidfiles. It is assumed that
161 the pidfiles are only updated at process creation time, and
162 not later. The first line of this file should be the ASCII
163 representation of the PID; a terminating newline is optional.
164 Any lines other than the first line are not examined.
168 Optional, used IN PLACE of processname, config, and pidfile.
169 If it exists, then a proper reload-if-necessary cycle may be
170 acheived by running these commands:
172 command=$(/etc/rd.d/init.d/SCRIPT probe)
173 [ -n "$command" ] && /etc/rc.d/init.d/SCRIPT $command
175 where SCRIPT is the name of the service's sysv init script.
177 Scripts that need to do complex processing could, as an
178 example, return "run /var/tmp/<servicename.probe.$$"
179 and implement a "run" command which would execute the
180 named script and then remove it.
182 Note that the probe command should simply "exit 0" if nothing
183 needs to be done to bring the service into sync with its
186 Copyright (c) 1998 Red Hat Software, Inc.
187 Modified Corrected & Overlooked by PLD Linux (r) Team 1999.