Background:
1.All services script are stored under : /etc/init.d
2.runlevel options:
use "runlevel" to check which level the os is running.
there are 6 runlevels:
0: shutdown.
1: single user mode.
2: multi user under a command line mode without NET connection .
3: compared to 2, with NET connection.
4: not avaiable.
5: multi user with Xwindow.
6: reboot
3.Services are corresponding to runlevel by means of store links under /etc/rc<runlevel>.d
4.links name as a format of "S/K<order><serviceName>":
S indicates "startup service", while K means "kill service".
order is the priority to start the service compared to other services.
sysv-rc-conf usage:
Steps:
put your script(e.g. a file named "hadoop" ) into the dir of "/etc/init.d", hence we get a service(e.g hadoop).
start the software by "sysv-rc-conf", enter into the service mgt gui.
3. choose runlevels for service scenarios of start-up and stop(if needed).
4. service register done. now you can test it by restart server(test auto-start-up) or shutdown(end service).
chkconfig usage:
1. put your script(e.g. a file named "hadoop" ) into the dir of "/etc/init.d", hence we get a service(e.g hadoop).
note: you script should provode startup/stop runlevel info by comments(Default-Start and Default-Stop), take OenTSDB service(a script with the path of "/etc/init.d/opentsdb") for example:
#!/bin/sh -e
#
# Modified from original source: Elastic Search
# https://github.com/elasticsearch/elasticsearch
# Thank you to the Elastic Search authors
#
### BEGIN INIT INFO
# Provides: opentsdb
# Required-Start: $network $named
# Required-Stop: $network $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts OpenTSDB TSD
# Description: Starts an OpenTSDB time series daemon
### END INIT INFO
PATH=/bin:/usr/bin:/sbin:/usr/sbin
2. execute following command to register a service:
chkconfig --add hadoop
3. set the runlevel for the new added service by:
chkconfig --level 2345 hadoop on
chkconfig --level 06 hadoop off
note : after the execution of this step, we can see soft link created under dir "/etc/rc<runlevel>.d":
mose@mose-vritual:/etc/rc3.d$ ll
total 20
drwxr-xr-x 2 root root 4096 3月 25 00:10 ./
drwxr-xr-x 131 root root 12288 3月 22 22:01 ../
-rw-r--r-- 1 root root 677 10月 16 17:30 README
lrwxrwxrwx 1 root root 18 3月 11 16:58 S01opentsdb -> ../init.d/opentsdb*
.....
lrwxrwxrwx 1 root root 18 3月 9 10:39 S05rc.local -> ../init.d/rc.local*
lrwxrwxrwx 1 root root 16 3月 25 00:10 S20hadoop -> ../init.d/hadoop*
update-rc.d
this is another service mgt software, which is also very easy to use.
Above all, we get a new service registered. since the script of /etc/init.d/hadoop can accept different opeation args, following command can be supported by this service.
service hadoop start/stop/restart/status