Moxa TC-6110-T-LX [15/117] Managing services with insserv

Moxa TC-6110-T-LX [15/117] Managing services with insserv
TC-6110 Linux User's Manual Basic Platform Configuration
2-8
Managing Services with insserv
Linux services can be started or stopped using of the scripts in /etc/init.d/. If you want to start up some
service, you can use insserv to add or remove the service to a specific run level. This tutorial shows you how
to add or remove a service from a specified run level.
WARNING
Insserve is a low level tool, and when improperly called can result in an unbootable system. For this reason,
current Debian best practices recommends against the use of insserv. If you do not feel comfortable using such
a low
-level tool, use update-rc.d instead. A good summary of how to use update-rc.d is available here:
http://www.debuntu.org/how
-to-managing-services-with-update-rc-d/ (Nov. 2013)
The example will use a services start-stop utility named tcps2, which we shall add to /etc/init.d/.
# !/bin/sh
### BEGIN INIT INFO
# Provides: tcps2
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: tcps2
### END INIT INFO
. /lib/lsb/init-functions
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
case "$1" in
start)
start-stop-daemon --start --quiet --oknodo --pidfile /var/run/tcps2.pid
--exec /usr/sbin/tcps2
;;
stop)
start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/tcps2.pid
;;
esac
exit 0
After creating the script, you will now add it as a scheduled service using insserv.
To add tcps2 as a service that will start at boot time and run at every runlevel, use the following syntax:
moxa@MOXA:~#sudo insserv -v -d tcps2
Check to see that the script has been added to each run level:
moxa@MOXA:~#ls -l /etc/rc?.d/*tcps*
lrwxrwxrwx 1 root root 15 Jul 6 09:40 /etc/rc2.d/S18tcps2 -> ../init.d/tcps2
lrwxrwxrwx 1 root root 15 Jul 6 09:40 /etc/rc3.d/S18tcps2 -> ../init.d/tcps2
lrwxrwxrwx 1 root root 15 Jul 6 09:40 /etc/rc4.d/S18tcps2 -> ../init.d/tcps2
lrwxrwxrwx 1 root root 15 Jul 6 09:40 /etc/rc5.d/S18tcps2 -> ../init.d/tcps2
To remove a service from inittab, use this command:
moxa@MOXA:~#insserv -r tcps2

Содержание

Похожие устройства

Скачать