zoukankan      html  css  js  c++  java
  • 关于Linux启动文件rc.local的解惑

    背景

    首先,rc.local是Linux启动程序在login程序前执行的最后一个脚本,有的服务器中在rc.local中可能会有一句touch /var/lock/subsys/local,这是干什么的呢,在百度中没找到,最终在Linuxquestions.org论坛成功找到满意的解答。

    touch

    首先要了解touch这个命令是做什么用的,在此用于创建一个不存在的文件,详细了解请见Linux touch命令

    解释

    /var/lock/subsys/local这个文件的存在证明rc.local这个脚本已经执行过了,目的在于避免这个脚本重复执行,除非这个文件不存在时,它才失效,也就是当系统关闭(shut down)时会发生,翻译的不是很好,原文是

    What this does is create a lock file that tells the system that ‘local’ is up and running already. It prevents the script from being run twice, as it will fail until the lockfile is removed, which will happen when you shut down.

    Typically this is used with bigger services such as database servers and so forth to make sure they are not started twice.

    这样做的目的是用于一些大型服务,例如数据库服务器,以确保它不会启动两次的情况出现。 
    至于touch出的这个文件什么时候被读取以避免再次生成,论坛两哥们是这么解释的

    To tell the truth I don’t think anything looks there. I have never seen a lock mechanism in place for the rc.local script. Like I was saying, usually it is only used for bigger services. However, it is usually checked by the script itself. 
    If you have a look at one of your more complicated rc scripts you may see in the ‘start’ function something like (pseudo code): 
    Code:

    start() {
        if /var/lock/subsys/myapp exists; then
            echo "myapp already started"
            exit
        else
             touch /var/lock/subsys/myapp
             /command/to/start/myapp
        fi
    }
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    也就是会在一个地方,会有类似与上面start()这样的方法会去判断是否已经存在一个local文件,如果有就不重复创建,如果没有就创建一个,后面再读取的时候就不会去创建,以此避免系统重复启动。

  • 相关阅读:
    Java练习 SDUT-3328_JAVA判断合法标识符
    问题2:css图片、文字居中
    问题1:jquery实现全选功能,第二次失效(已解决)
    问题2:input、textarea、submit 宽度设置为100%,但显示宽度不一致
    问题1:设置了text-overflow : ellipsis未起作用
    问题1:canvas绘制图片加载不出来
    问题1:鼠标指向导航栏li,但li中a样式未改变
    Shell工具| 流程控制
    Hadoop |集群的搭建
    MySQL高级01
  • 原文地址:https://www.cnblogs.com/zhoading/p/9666948.html
Copyright © 2011-2022 走看看