zoukankan      html  css  js  c++  java
  • linux启动的run-level

    我们可以经常看见在系统etc/init.d里面的script都有run-level这种说法,比如:

     1 #! /bin/sh
     2 
     3 ### BEGIN INIT INFO
     4 # Provides:     sshd
     5 # Required-Start:   $remote_fs $syslog
     6 # Required-Stop:    $remote_fs $syslog
     7 # Default-Start:    2 3 4 5
     8 # Default-Stop:     
     9 # Short-Description:    OpenBSD Secure Shell server
    10 ### END INIT INFO

    里面的 Default-Start: 2 3 4 5 是什么意思呢?

    这就是run-level.

    其中的数字的意思就是:

    • 0 停机
    • 1 单用户,Does not configure network interfaces, start daemons, or allow non-root logins
    • 2 多用户,无网络连接 Does not configure network interfaces or start daemons
    • 3 多用户,启动网络连接 Starts the system normally.
    • 4 用户自定义
    • 5 多用户带图形界面
    • 6 重启

    具体的参考(wiki): http://zh.wikipedia.org/wiki/%E8%BF%90%E8%A1%8C%E7%BA%A7%E5%88%AB

    那么我们怎么轻易的将我们自己的程序加入到linux系统启动项呢?

    我们可以用update-rc.d (under Ubuntu), chkconfig (under redhat)

           update-rc.d [-n] [-f] name remove
    
           update-rc.d [-n] name defaults [NN | SS KK]
    
           update-rc.d [-n] name start|stop NN runlevel [runlevel]...  .  start|stop NN runlevel [runlevel]...  . ...
    
           update-rc.d [-n] name disable|enable [ S|2|3|4|5 ]

    这里面的NN是一个两位数的整数, 他决定了在同级的启动项里, 这个进程的启动优先级. 默认是20.

    也就是说, 如果我们有两个进程需要启动, A和B. 但是A必须比B先启动, 而且在关闭的时候B必须比A先关闭,我们就可以利用这个NN进行优先级的控制.

    举一个例子:

    1   update-rc.d foo-1 start 20 2 3 4 5 . stop 20 0 1 6 .
    2 
    3   update-rc.d foo-2 start 30 2 3 4 5 . stop 10 0 1 6 .

    我们可以看见foo-1比foo-2先启动,但是却后关闭~

  • 相关阅读:
    html 时间区间选择功能
    Django 【settings】数据库设置
    Django forms 定制form字段
    避免js全局变量污染的方法
    js获取路由
    采用遍历的方法获取字符串a在字符串b中的位置
    vue 学习笔记
    Promise
    js常用JSON数据操作
    js 数组遍历方式
  • 原文地址:https://www.cnblogs.com/linehrr-freehacker/p/3351371.html
Copyright © 2011-2022 走看看