How to write a service script ?

来源:百度文库 编辑:神马文学网 时间:2024/04/19 14:32:42
Service script is used to start a service when system booting up. It should be placed under /etc/init.d .
chkconfig is used to install a service script into different runlevels or remove it from certain runlevels. With --list option it can also let you find out certain service script will be started up in certain runlevels.
Service script must include at least two comment lines which are instructions to chkconfig. Fail to do so will let chkconfig complain about "service xxxx doesn‘t support chkconfig". To cite the man page of chkcnfig:
Each service  which  should be manageable by chkconfig needs two or more commented lines added to its init.d script. The first line tells chkconfig what runlevels the service should be started in by default, as well as the start and stop priority levels. If  the  service  should  not, by default, be started in any runlevels, a - should be used in place of the runlevels list.
The second line contains a description for the service, and may be extended across multiple lines with backslash continuation.
For example, random.init has these three lines:
# chkconfig: 2345 20 80
# description: Saves and restores system entropy pool for \
# higher quality random number generation.
This says that the random script should be started in levels 2, 3, 4, and 5, that its start priority should be 20, and that its stop priority should be 80.  You should be able to figure out what the description says; the \ causes the line to be continued. The extra space in front of the line is ignored.