发表于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. 【转】COCOS2D-X之不断变化的数字效果Demo

    我们在玩"天天爱消除"或"天天连萌"的时候,每玩一盘后会有一个游戏结果界面,上面有一个显示所得分数的效果.今天我们这个Demo就是要实现与之相近的效果. 一.我 ...

  2. 【转】angular通过$http与服务器通信

    http://www.cooklife.cn/detail/54c5044ec93620284e964b58#View angular是一个前端框架,实现了可交互式的页面,但是对于一个web应用,页面 ...

  3. 记录一次Jmeter性能测试

    一.引言 之前有总结过如何写Java请求测试用例类,写完测试脚本调通之后,信心满满地以为我准备好可以开始性能测试了.结果在评审测试计划的时候,当即被项目组狠狠的扇了一耳光,各种不确定的点:性能指标不明 ...

  4. js实现收缩菜单效果

    废话不多说,直接上代码: 有注释 <head> <title></title> <style type="text/css"> di ...

  5. 开源了一个iOS输入控件【原】

    1.Github 地址:https://github.com/linyc/InputBarFollowKeyboard 2.说明文档:https://github.com/linyc/InputBar ...

  6. [LeetCode] Two Sum水过

    刷LeetCode的第一题,TwoSum,基本算是水过. 题目:https://leetcode.com/problems/two-sum/ Given an array of integers, f ...

  7. MFC菜单、工具栏和状态栏

    菜单:CMenu类 CMenu类的主要成员函数 BOOL LoadMenu(UINT nIDResource); 加载菜单资源,并将其附加到CMenu对象上.参数nIDResource指定了要加载的菜 ...

  8. 45种Javascript技巧大全(转)

      6.小心使用typeof.instanceof和constructor typeof:不要忘了typeof null返回object,而大多数对象,typeof(Array, Date, and ...

  9. 深度学习 CNN CUDA 版本2

    作者:zhxfl 邮箱:zhxfl##mail.ustc.edu.cn 主页:http://www.cnblogs.com/zhxfl/p/4155236.html 第1个版本blog在这里:http ...

  10. centos firefox中文乱码问题

    下载两个rpm包 fonts-chinese-3.02-9.6.e15.noarch.rpm fonts-ISO8859-2-75dpi-1.0-17.1.noarch.rpm 然后安装rmp rpm ...