关于Linux启动文件rc.local的解惑

解释

/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.

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
exit
else
touch /var/lock/subsys/myapp
/command/to/start/myapp
fi
}