Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

12.10. Debian/Ubuntu

12.10.1. update-rc.d - install and remove System-V style init script links

for example:

Insert links using the defaults:
   update-rc.d foobar defaults
Equivalent command using explicit argument sets:
   update-rc.d foobar start 20 2 3 4 5 . stop 20 0 1 6 .
More typical command using explicit argument sets:
   update-rc.d foobar start 30 2 3 4 5 . stop 70 0 1 6 .
Insert links at default runlevels when B requires A
   update-rc.d script_for_A defaults 80 20
   update-rc.d script_for_B defaults 90 10
Insert a link to a service that (presumably) will not be needed by any other daemon
   update-rc.d top_level_app defaults 98 02
Insert links for a script that requires services that start/stop at sequence number 20
   update-rc.d script_depends_on_svc20 defaults 21 19
Remove all links for a script (assuming foobar has been deleted already):
   update-rc.d foobar remove
Example of disabling a service:
   update-rc.d -f foobar remove
   update-rc.d foobar stop 20 2 3 4 5 .
Example of a command for installing a system initialization-and-shutdown script:
   update-rc.d foobar start 45 S . stop 31 0 6 .
Example of a command for disabling a system initialization-and-shutdown script:
   update-rc.d -f foobar remove
   update-rc.d foobar stop 45 S .
		

set default

update-rc.d nginx defaults
		

remove

update-rc.d -f lighttpd remove
$ sudo update-rc.d -f avahi-daemon remove
		

12.10.2. invoke-rc.d - executes System-V style init script actions

$ sudo invoke-rc.d mysql restart
		

12.10.3. runlevel

$ runlevel
N 2

# runlevel
N 3
		
$ sudo vim /etc/init.d/rcS
#! /bin/sh
#
# rcS
#
# Call all S??* scripts in /etc/rcS.d/ in numerical/alphabetical order
#

exec /etc/init.d/rc S
		

the default is S (/etc/rcS.d/)

the redhat linux in the /etc/inittab

switch runlevel

/etc/init.d/rc 3
		

12.10.4. sysv-rc-conf

(ubuntu下sysv-rc-conf命令等同redhat下chkconfig命令)

$ sudo apt-get install sysv-rc-conf
		

进入sysv-rc-conf TUI用户界面,你可以使用键盘方向键切换,使用空格键选择“X”表示选中,这个软件也支持鼠标操作。

$ sudo sysv-rc-conf
		
sysv-rc-conf gmond on
sysv-rc-conf --list gmond
		

12.10.5. xinetd - replacement for inetd with many enhancements

$ sudo apt-get install xinetd
		

12.10.5.1. tftpd

apt-get install xinetd
apt-get install tftpd tftp
			

/etc/xinetd.d/tftp

service tftp
{
	disable=no
	socket_type=dgram
	protocol =udp
	wait=yes
	user=root
	server=/usr/sbin/in.tftpd
	server_args =-s /home/neo/tftpboot -c
	per_source=11
	cps=100 2
	flags=IPv4
}
			

12.10.6. Scheduled Tasks

12.10.6.1. crontab - maintain crontab files for individual users

To see what crontabs are currently running on your system, you can open a terminal and run:

$  crontab -l
# m h  dom mon dow   command
#* */30 * * * /home/neo/dyndns
			

if you want to see root user, please add 'sudo' in the prefix.

To edit the list of cron jobs you can run:

$ crontab -e
			

As you can see there are 5 stars. The stars represent different date parts in the following order:

  1. minute (from 0 to 59)

  2. hour (from 0 to 23)

  3. day of month (from 1 to 31)

  4. month (from 1 to 12)

  5. day of week (from 0 to 6) (0=Sunday)

By default cron jobs sends a email to the user account executing the cronjob. If this is not needed put the following command At the end of the cron job line .

			
>/dev/null 2>&1
			
			

12.10.6.2. at, batch, atq, atrm - queue, examine or delete jobs for later execution

12.10.7. sv - control and manage services monitored by runsv

services directory /etc/service/

$ sudo sv start git-daemon
ok: run: git-daemon: (pid 10323) 1s

$ sudo sv restart git-daemon
ok: run: git-daemon: (pid 10327) 1s

$ sudo sv stop git-daemon
ok: down: git-daemon: 1s, normally up
		

12.10.7.1. runsv

$ sudo runsv git-daemon
			

12.10.7.2. runsvdir

运行/etc/service目录下的所有服务

			
$sudo runsvdir /etc/service &