发表于1年前(2013-01-08 13:01)   阅读(2380) | 评论(0) 2人收藏此文章, 我要收藏
赞0

熟悉debian系统的应该经常会用到update-rc.d这个命令,它与redhat里的chkconfig 是相似的管理服务的工具,首先来看下这个命令的使用方法:

1
2
3
4
5
6
root@10.1.1.200:etc# update-rc.d --help
usage: update-rc.d [-n] [-f] <basename> remove
       update-rc.d [-n] <basename> defaults [NN | SS KK]
       update-rc.d [-n] <basename> start|stop NN runlvl [runlvl] [...] .
        -n: not really
        -f: force

虽然debian的update-rc.d与RH的chkconfig工具相类似。不同的是chkconfig是一个二进制程序,而update-rc.d是一个Perl脚本。这些工具有不同的命令行选项,但是却执行类似的功能。下表列出了update-rc.d的一些用法。

命令                                                                    功能
update-rc.d -f <service> remove                        从所有的运行级别配置目录中是删除指定的服务
update-rc.d <service> start <order> <runlevels>   配置服务在运行级别列表中按指定的顺序启动
update-rc.d <service> stop <order> <runlevels>    配置服务在运行级别列表中指定的顺序停止

例如,下面的命令序列与命令chkconfig --level 345 apache2 on的作用相同:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
root@10.1.1.200:etc# update-rc.d -f apache2 remove
 Removing any system startup links for /etc/init.d/apache2 ...
   /etc/rc0.d/K09apache2
   /etc/rc1.d/K09apache2
   /etc/rc2.d/S91apache2
   /etc/rc3.d/S91apache2
   /etc/rc4.d/S91apache2
   /etc/rc5.d/S91apache2
   /etc/rc6.d/K09apache2
root@10.1.1.200:etc# update-rc.d  apache2  start 20 3 4 5 . stop 20 0 1 2 6 .
 Adding system startup for /etc/init.d/apache2 ...
   /etc/rc0.d/K20apache2 -> ../init.d/apache2
   /etc/rc1.d/K20apache2 -> ../init.d/apache2
   /etc/rc2.d/K20apache2 -> ../init.d/apache2
   /etc/rc6.d/K20apache2 -> ../init.d/apache2
   /etc/rc3.d/S20apache2 -> ../init.d/apache2
   /etc/rc4.d/S20apache2 -> ../init.d/apache2
   /etc/rc5.d/S20apache2 -> ../init.d/apache2
1
2
3
4
5
6
7
8
9
10
11
12
root@10.1.1.200:etc# ls -l /etc/rc3.d/
total 4
lrwxrwxrwx 1 root root  16 2012-08-13 21:29 K20vsftpd -> ../init.d/vsftpd
-rw-r--r-- 1 root root 556 2008-08-12 22:09 README
lrwxrwxrwx 1 root root  17 2012-08-06 00:11 S10rsyslog -> ../init.d/rsyslog
lrwxrwxrwx 1 root root  15 2012-08-06 00:12 S12acpid -> ../init.d/acpid
lrwxrwxrwx 1 root root  14 2012-08-06 00:30 S12dbus -> ../init.d/dbus
lrwxrwxrwx 1 root root  13 2012-08-06 00:24 S16ssh -> ../init.d/ssh
lrwxrwxrwx 1 root root  23 2012-08-06 00:26 S17mysql-ndb-mgm -> ../init.d/mysql-ndb-mgm
lrwxrwxrwx 1 root root  19 2012-08-06 00:26 S18mysql-ndb -> ../init.d/mysql-ndb
lrwxrwxrwx 1 root root  15 2012-08-06 00:26 S19mysql -> ../init.d/mysql
lrwxrwxrwx 1 root root  17 2013-01-08 00:21 S20apache2 -> ../init.d/apache2

第一个命令移除了所有的指向/etc/init.d/apache2服务脚本的运行级别链接,-f标志将会使得update-rc.d即使在apache2脚本本身已经存在的情况仍然进行相应的处理。第二个命令在每一个运行级别创建了一个服务级别为20的启动/停止脚本。这些脚本的连接位于/etc/rcX.d/LnName,对应脚本位于/etc/init.d/Script-name。对于已经存的启动脚本链接, 如再次执行第二个命令会发现 System startup links for /etc/init.d/apache2 already exist,必须将其remove掉,再进行相关的操作。

start 20  3 4 5 . : 表示在3,4,5这三个运行级别中,按先后顺序,由小到大,第20个开始运行这个脚本。
         stop 20 0 1 2 6 . :表示在0,1,2,6这四个运行级别中,按照先后顺序,由小到大,第20个停止这个脚本的运行。

有个问题就是想要知道某服务处于什么开机启动级别,man update-rc.d也没发现有该选项。只能从/etc/rcX.d去查看。

其实熟悉RH 的chkconfig,在debian中也提供类似的工具,sysv-rc-conf同样是查看所有服务的启动状态.

下面安装sysv-rc-conf

1
root@10.1.1.200:etc# apt-get install sysv-rc-conf
1
2
3
4
5
6
7
8
9
root@10.1.1.200:etc# sysv-rc-conf --list
acpid        1:off  2:on    3:on    4:on    5:on
apache2      0:off  1:off   2:off   3:on    4:on    5:on    6:off
atd          0:off  1:off   2:on    3:on    4:on    5:on    6:off
bootlogd     S:on
cron         1:off  2:on    3:on    4:on    5:on
dbus         1:off  2:on    3:on    4:on    5:on
exim4        0:off  1:off   2:on    3:on    4:on    5:on    6:off
fam          0:off  1:off   2:on    3:on    4:on    5:on    6:off

是不是很熟悉..

1
2
3
root@10.1.1.200:etc# sysv-rc-conf --level 234 apache2 off
root@10.1.1.200:etc# sysv-rc-conf --list apache2
apache2      0:off  1:off   2:off   3:off   4:off   5:on    6:off

原 Debian设置开机自动启动与关闭的更多相关文章

  1. Mongodb 启动关闭脚本并设置开机自动启动Mongodb

    配置文件内容:[root@yoon etc]# cat mongod.conf logpath=/export/log/mongodb.loglogappend=truefork = truedbpa ...

  2. CentOS 7.6 RPM 方式安装Oracle19c 后 使用 systemd 的方式设置开机自动启动Oracle数据库

    1. 方法简介: 使用systemd 来进行 oracle数据库的启动和关闭操作. 使用的脚本为 lsnrctl和dbstart 2. 修改事项. 需要先修改一下 oracle 的启动脚本配置: vi ...

  3. CentOS设置开机自动启动某服务

    CentOS设置开机自动启动某服务   这里以启动sshd服务为例:   查看sshd是否已经是系统服务:   # chkconfig --list |grep sshd 会显示:  sshd     ...

  4. centos下安装memcached并设置开机自动启动-两种方法

    方法一: 安装memcachedyum install memcached 启动服务并初始化service memcached start -p 11211 -l 127.0.0.1 -d 设置mem ...

  5. VMware ESXi 6.7服务器设置开机自动启动虚拟机

    VMware ESXi 6.7服务器设置开机自动启动虚拟机,具体操作步骤如下 1.登陆到VMware ESXi 6.7  web 界面 2.导航器-->主机-->管理  将自动启动修改为 ...

  6. [转] ubuntu16.04添加系统 service, 并设置开机自动启动

    转:https://www.jianshu.com/p/1958878646bd 1. 创建pfly.service文件 2.  执行 systemctl daemon-reload 3. 执行 sy ...

  7. 在Linux环境安装redis步骤,且设置开机自动启动redis

    最近在linux环境安装了redis学习,目前已经安装成功且设置开机即启动状态,我把步骤流程记录了下来,分享给需要的小伙伴. 1.我在/usr/local/localsoftware/目录下创建了一个 ...

  8. win10如何设置开机自动启动热点WIFI?

    1.编写脚本文件(先新建txt文件,编写代码内容netsh wlan start hostednetwork,最后重命名成HotSpot.bat):文件名称:HotSpot.bat,代码内容: net ...

  9. Centos7下源编译安装Postgresql 并设置开机自动启动postgresql.serivce 服务相关研究

    编写开机自动启动服务脚本: # cat >> /usr/lib/systemd/system/postgresql.service >> EOF [Unit] Descript ...

随机推荐

  1. Java [Leetcode 273]Delete Node in a Linked List

    题目描述: Write a function to delete a node (except the tail) in a singly linked list, given only access ...

  2. Java [leetcode 24]Swap Nodes in Pairs

    题目描述: Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1-& ...

  3. BigRender

    当一个网站越来越庞大,加载速度越来越慢的时候,开发者们不得不对其进行优化,谁愿意访问一个需要等待 10 秒,20 秒才能出现的网页呢? 常见的也是相对简单易行的一个优化方案是 图片的延迟加载.一个庞大 ...

  4. JMX-JAVA进程监控利器

    Java 管理扩展(Java Management Extension,JMX)是从jdk1.4开始的,但从1.5时才加到jdk里面,并把API放到java.lang.management包里面. 如 ...

  5. Explain 结果解读与实践

    Explain 结果解读与实践 基于 MySQL 5.0.67 ,存储引擎 MyISAM . 注:单独一行的"%%"及"`"表示分隔内容,就象分开“第一章”“第 ...

  6. 25、BroadCastRecevier

    BroadCastRecevier 有两种注册方式 1. 清单文件里注册: 一旦应用程序被部署到手机, 广播接受者就会生效 2. 代码里面注册: 一旦代码所在的进程被杀死了, 广播接受者就失效了. 广 ...

  7. 在文件中读取、存储Json格式的字符串

    public class Weather { static readonly string FilePath = System.Environment.CurrentDirectory + @&quo ...

  8. 【暑假】[深入动态规划]UVa 10618 The Bookcase

    UVa 12099  The Bookcase 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=42067 思路:    ...

  9. Clean Code – Chapter 2: Meaningful Names

    Use Intention-Revealing Names The name should tell you why it exists, what it does, and how it is us ...

  10. 使用X-UA-Compatible来设置IE兼容模式

    转自:http://www.cnblogs.com/libra/archive/2009/03/24/1420731.html 英文原文:http://msdn.microsoft.com/en-us ...