Home | 簡體中文 | 繁體中文 | 雜文 | Search | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 作品與服務 | Email

第 16 章 設備管理

目錄

16.1. Debian/Ubuntu
16.1.1. update-rc.d - install and remove System-V style init script links
16.1.2. invoke-rc.d - executes System-V style init script actions
16.1.3. runlevel
16.1.4. sysv-rc-conf
16.1.5. xinetd - replacement for inetd with many enhancements
16.1.5.1. tftpd
16.1.6. Scheduled Tasks
16.1.6.1. crontab - maintain crontab files for individual users
16.1.6.2. at, batch, atq, atrm - queue, examine or delete jobs for later execution
16.1.7. sv - control and manage services monitored by runsv
16.1.7.1. runsv
16.1.7.2. runsvdir
16.2. Services
16.2.1. systemctl
16.2.1.1. is-enabled 查看當前服務的啟用狀態
16.2.1.2. 重載 systemd
16.2.1.3. 列出啟動失敗的服務
16.2.1.4. list-units
16.2.2. service
16.2.2.1. chkconfig
16.2.3. xinetd.d
16.2.3.1. tftpd
16.2.3.2. rsync
16.2.3.3. rshd
16.2.4. rpcinfo
16.2.5. SELINUX

16.1. Debian/Ubuntu

16.1.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
		

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

$ sudo invoke-rc.d mysql restart
		

16.1.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
		

16.1.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
		

16.1.5. xinetd - replacement for inetd with many enhancements

$ sudo apt-get install xinetd
		

16.1.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
}
			

16.1.6. Scheduled Tasks

16.1.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
			
			

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

16.1.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
		

16.1.7.1. runsv

$ sudo runsv git-daemon
			

16.1.7.2. runsvdir

運行/etc/service目錄下的所有服務

			
$sudo runsvdir /etc/service &
			
			
comments powered by Disqus