]>
Commit | Line | Data |
---|---|---|
7e04fe0e | 1 | Writing System V init scripts for PLD Linux |
12de71be | 2 | =============================================== |
3 | ||
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 | |
6 | ".init" suffix. | |
7 | ||
8 | ||
9 | Sample Script | |
10 | ============= | |
11 | ||
7e04fe0e | 12 | #!/bin/sh |
12de71be | 13 | # |
14 | # /etc/rc.d/init.d/<servicename> | |
15 | # | |
16 | # <description of the *service*> | |
17 | # <any general comments about this init script> | |
18 | # | |
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.> | |
24 | ||
25 | # Source function library. | |
26 | . /etc/rc.d/init.d/functions | |
27 | ||
7e04fe0e | 28 | # Running service -- nice level. |
29 | if [ -f /etc/sysconfig/<service> ]; then | |
30 | . /etc/sysconfig/<service> | |
31 | fi | |
32 | ||
12de71be | 33 | <define any local shell functions used by the code that follows> |
34 | ||
35 | case "$1" in | |
36 | start) | |
7e04fe0e | 37 | show Starting <servicename> services |
12de71be | 38 | <start daemons, perhaps with the daemon function> |
39 | touch /var/lock/subsys/<servicename> | |
40 | ;; | |
41 | stop) | |
7e04fe0e | 42 | show Shutting down <servicename> services |
12de71be | 43 | <stop daemons, perhaps with the killproc function> |
44 | rm -f /var/lock/subsys/<servicename> | |
45 | ;; | |
46 | status) | |
47 | <report the status of the daemons in free-form format, | |
48 | perhaps with the status function> | |
49 | ;; | |
50 | restart) | |
51 | <restart the daemons, normally with $0 stop; $0 start> | |
52 | ;; | |
53 | reload) | |
54 | <cause the service configuration to be reread, either with | |
55 | kill -HUP or by restarting the daemons, possibly with | |
56 | $0 stop; $0 start> | |
57 | ;; | |
58 | probe) | |
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.> | |
64 | ;; | |
65 | *) | |
7e04fe0e | 66 | echo "Usage: $0 {start|stop|status|reload|restart[|probe]" |
12de71be | 67 | exit 1 |
68 | ;; | |
69 | esac | |
70 | ||
71 | ||
72 | Notes: the restart and reload functions may be (and commonly are) | |
73 | combined into one test, vis: | |
74 | restart|reload) | |
75 | You are not prohibited from adding other commands; list all commands | |
76 | which you intend to be used interactively to the usage message. | |
77 | ||
78 | ||
79 | ||
80 | Functions in /etc/rc.d/init.d/functions | |
81 | ======================================= | |
82 | ||
83 | daemon [+/-nicelevel] program [arguments] [&] | |
84 | ||
7e04fe0e | 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. | |
12de71be | 88 | |
89 | killproc program [signal] | |
90 | ||
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 | |
93 | seconds later. | |
94 | ||
95 | It also tries to remove the pidfile, if it finds one. | |
96 | ||
97 | pidofproc program | |
98 | ||
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 | |
102 | scripts. | |
103 | ||
104 | status program | |
105 | ||
106 | Prints status information. Assumes that the program name is | |
107 | the same as the servicename. | |
108 | ||
109 | ||
110 | Tags | |
111 | ==== | |
112 | ||
113 | # chkconfig: <startlevellist> <startpriority> <endpriority> | |
114 | ||
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. | |
120 | ||
121 | Unless there is a VERY GOOD, EXPLICIT reason to the | |
122 | contrary, the <endpriority> should be equal to | |
123 | 100 - <startpriority> | |
124 | ||
125 | # description: <multi-line description of service> | |
126 | ||
127 | Required. Several lines of description, continued with '\' | |
128 | characters. The initial comment and following whitespace | |
129 | on the following lines is ignored. | |
130 | ||
131 | # description[ln]: <multi-line description of service in the language \ | |
132 | # ln, whatever that is> | |
133 | ||
134 | Optional. Should be the description translated into the | |
135 | specified language. | |
136 | ||
137 | # processname: | |
138 | ||
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: | |
142 | # processname: smdb | |
143 | # processname: nmdb | |
144 | ||
145 | # config: | |
146 | ||
147 | Optional, multiple entries allowed. For each static config | |
148 | file used by the daemon, use a single entry. For example: | |
7e04fe0e | 149 | # config: /etc/httpd/httpd.conf |
150 | # config: /etc/httpd/srm.conf | |
12de71be | 151 | |
152 | Optionally, if the server will automatically reload the config | |
153 | file if it is changed, you can append the word "autoreload" to | |
154 | the line: | |
155 | # config: /etc/foobar.conf autoreload | |
156 | ||
157 | # pidfile: | |
158 | ||
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. | |
165 | ||
166 | # probe: true | |
167 | ||
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: | |
171 | ||
172 | command=$(/etc/rd.d/init.d/SCRIPT probe) | |
173 | [ -n "$command" ] && /etc/rc.d/init.d/SCRIPT $command | |
174 | ||
175 | where SCRIPT is the name of the service's sysv init script. | |
176 | ||
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. | |
181 | ||
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 | |
184 | configuration files. | |
185 | ||
186 | Copyright (c) 1998 Red Hat Software, Inc. | |
ffe19b59 | 187 | Modified Corrected & Overlocked by PLD Linux (r) Team 1999. |