]> git.pld-linux.org Git - projects/rc-scripts.git/blame - doc/sysvinitfiles
- preparation for upcoming 0.4.0.1 release
[projects/rc-scripts.git] / doc / sysvinitfiles
CommitLineData
7e04fe0e 1Writing System V init scripts for PLD Linux
ec8b15cb 2$Id$
12de71be 3===============================================
4
5All System V init scripts are named /etc/rc.d/init.d/<servicename>
6where <servicename> is the name of the service. There must be no
7".init" suffix.
8
9
10Sample Script
11=============
12
7e04fe0e 13#!/bin/sh
12de71be 14#
15# /etc/rc.d/init.d/<servicename>
16#
17# <description of the *service*>
18# <any general comments about this init script>
19#
20# <tags -- see below for tag definitions. *Every line* from the top
21# of the file to the end of the tags section must begin with a #
22# character. After the tags section, there should be a blank line.
23# This keeps normal comments in the rest of the file from being
24# mistaken for tags, should they happen to fit the pattern.>
25
26# Source function library.
27. /etc/rc.d/init.d/functions
28
7e04fe0e 29# Running service -- nice level.
30if [ -f /etc/sysconfig/<service> ]; then
31 . /etc/sysconfig/<service>
32fi
33
12de71be 34<define any local shell functions used by the code that follows>
35
36case "$1" in
37 start)
7e04fe0e 38 show Starting <servicename> services
12de71be 39 <start daemons, perhaps with the daemon function>
40 touch /var/lock/subsys/<servicename>
41 ;;
42 stop)
7e04fe0e 43 show Shutting down <servicename> services
12de71be 44 <stop daemons, perhaps with the killproc function>
45 rm -f /var/lock/subsys/<servicename>
46 ;;
47 status)
48 <report the status of the daemons in free-form format,
49 perhaps with the status function>
50 ;;
51 restart)
52 <restart the daemons, normally with $0 stop; $0 start>
53 ;;
54 reload)
55 <cause the service configuration to be reread, either with
56 kill -HUP or by restarting the daemons, possibly with
57 $0 stop; $0 start>
58 ;;
59 probe)
60 <optional. If it exists, then it should determine whether
61 or not the service needs to be restarted or reloaded (or
62 whatever) in order to activate any changes in the configuration
63 scripts. It should print out a list of commands to give to
64 $0; see the description under the probe tag below.>
65 ;;
66 *)
7e04fe0e 67 echo "Usage: $0 {start|stop|status|reload|restart[|probe]"
12de71be 68 exit 1
69 ;;
70esac
71
72
73Notes: the restart and reload functions may be (and commonly are)
74combined into one test, vis:
75 restart|reload)
76You are not prohibited from adding other commands; list all commands
77which you intend to be used interactively to the usage message.
78
79
80
81Functions in /etc/rc.d/init.d/functions
82=======================================
83
84daemon [+/-nicelevel] program [arguments] [&]
85
7e04fe0e 86 Obsoletes starts a daemon, if it is not already running.
87 Does other useful things like keeping the daemon from
88 dumping core if it terminates unexpectedly.
12de71be 89
90killproc program [signal]
91
92 Sends a signal to the program; by default it sends a SIGTERM,
93 and if the process doesn't die, it sends a SIGKILL a few
94 seconds later.
95
96 It also tries to remove the pidfile, if it finds one.
97
98pidofproc program
99
100 Tries to find the pid of a program; checking likely pidfiles,
101 using the pidof program, or even using ps. Used mainly from
102 within other functions in this file, but also available to
103 scripts.
104
105status program
106
107 Prints status information. Assumes that the program name is
108 the same as the servicename.
109
110
111Tags
112====
113
114# chkconfig: <startlevellist> <startpriority> <endpriority>
115
116 Required. <startlevellist> is a list of levels in which
117 the service should be started by default. <startpriority>
118 and <endpriority> are priority numbers. For example:
119 # chkconfig: 2345 20 80
120 Read 'man chkconfig' for more information.
121
122 Unless there is a VERY GOOD, EXPLICIT reason to the
123 contrary, the <endpriority> should be equal to
124 100 - <startpriority>
125
126# description: <multi-line description of service>
127
128 Required. Several lines of description, continued with '\'
129 characters. The initial comment and following whitespace
130 on the following lines is ignored.
131
132# description[ln]: <multi-line description of service in the language \
133# ln, whatever that is>
134
135 Optional. Should be the description translated into the
136 specified language.
137
138# processname:
139
140 Optional, multiple entries allowed. For each process name
141 started by the script, there should be a processname entry.
142 For example, the samba service starts two daemons:
143 # processname: smdb
144 # processname: nmdb
145
146# config:
147
148 Optional, multiple entries allowed. For each static config
149 file used by the daemon, use a single entry. For example:
7e04fe0e 150 # config: /etc/httpd/httpd.conf
151 # config: /etc/httpd/srm.conf
12de71be 152
153 Optionally, if the server will automatically reload the config
154 file if it is changed, you can append the word "autoreload" to
155 the line:
156 # config: /etc/foobar.conf autoreload
157
158# pidfile:
159
160 Optional, multiple entries allowed. Use just like the config
161 entry, except that it points at pidfiles. It is assumed that
162 the pidfiles are only updated at process creation time, and
163 not later. The first line of this file should be the ASCII
164 representation of the PID; a terminating newline is optional.
165 Any lines other than the first line are not examined.
166
167# probe: true
168
169 Optional, used IN PLACE of processname, config, and pidfile.
170 If it exists, then a proper reload-if-necessary cycle may be
171 acheived by running these commands:
172
173 command=$(/etc/rd.d/init.d/SCRIPT probe)
174 [ -n "$command" ] && /etc/rc.d/init.d/SCRIPT $command
175
176 where SCRIPT is the name of the service's sysv init script.
177
178 Scripts that need to do complex processing could, as an
179 example, return "run /var/tmp/<servicename.probe.$$"
180 and implement a "run" command which would execute the
181 named script and then remove it.
182
183 Note that the probe command should simply "exit 0" if nothing
184 needs to be done to bring the service into sync with its
185 configuration files.
186
187Copyright (c) 1998 Red Hat Software, Inc.
7e04fe0e 188Modified Corrected & Overlocked by PLD (r) Team 1999.
This page took 0.151523 seconds and 4 git commands to generate.