关于Linux启动文件rc.local的解惑
来源:互联网 发布:top的域名注册 编辑:程序博客网 时间:2024/09/21 08:18
背景
首先,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}
也就是会在一个地方,会有类似与上面start()这样的方法会去判断是否已经存在一个local文件,如果有就不重复创建,如果没有就创建一个,后面再读取的时候就不会去创建,以此避免系统重复启动。
- 关于Linux启动文件rc.local的解惑
- 关于SuSE启动文件rc.local
- Linux的rc.local自启动服务
- Linux的rc.local自启动服务
- Linux的rc.local自启动服务
- Linux的rc.local自启动服务
- Linux的rc.local自启动服务
- Linux的rc.local自启动服务
- 解决Linux开机启动文件rc.local不能自动执行
- linux启动后执行脚本(/etc/rc.local文件)
- 树莓派的rc.local文件(设置开机启动)
- (转)Linux的rc.local自启动服务
- linux的开机启动过程(rc.local、init.d、rc.x、init的作用)
- Linux 中 rc.local、init.d、rc.x、init 这几个文件(夹)各有什么作用?启动执行的脚本应该均放在 rc.local 中吗?
- Linux 中 rc.local、init.d、rc.x、init 这几个文件(夹)各有什么作用?启动执行的脚本应该均放在 rc.local 中吗?
- linuxrc文件,rc.local文件,rcS文件,我的根文件系统启动脚本文件
- 关于ubuntu9.04启动文件rc.local、/etc/bash.bashrc、~/bashrc、/etc/profi...
- Update-rc.d && rc.local管理Ubuntu的开机启动
- scrollview嵌套listview的解决方法(一)
- (二叉树)谈一谈各类算法和数据结构的c++实现以及相关操作的复杂度(二)
- C语言基础
- Spring AOP 错误:Pointcut is malformed: Pointcut is not well-formed
- 167. Two Sum II
- 关于Linux启动文件rc.local的解惑
- http请求
- spring普通java工程的配置启动方式
- androidSimpleCache的详细讲解
- iOS自定义UICollectionViewLayout布局实现瀑布流
- Spring5.0.X源码阅读环境搭建Eclipse4.6.3(neon)
- PyQt简单例子: 包括ui文件生成, 代码, 打包exe
- [PAT乙级]1033. 旧键盘打字(20)
- Luogu P1328 [NOIP2014]生活大爆炸版石头剪刀布