Rov*_*ion 11 lsb init.d debian-wheezy
在 Debian 7 (Wheezy) 中 nginx 的初始化脚本中,我阅读了以下摘录:
status)
status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
;;
Run Code Online (Sandbox Code Playgroud)
此代码运行良好并sudo service nginx status输出[ ok ] nginx is running. 然而status_of_proc没有在 bash 中定义,也没有在 dash 中定义:
$ type status_of_proc
status_of_proc: not found
Run Code Online (Sandbox Code Playgroud)
虽然如果我将相同的检查插入到 nginx 脚本中,我会得到以下结果:
status_of_proc is a shell function
Run Code Online (Sandbox Code Playgroud)
在 init 文件本身上运行 bash 提供了进一步的解释:
status_of_proc is a function
status_of_proc ()
{
local pidfile daemon name status OPTIND;
pidfile=;
OPTIND=1;
while getopts p: opt; do
case "$opt" in
p)
pidfile="$OPTARG"
;;
esac;
done;
shift $(($OPTIND - 1));
if [ -n "$pidfile" ]; then
pidfile="-p $pidfile";
fi;
daemon="$1";
name="$2";
status="0";
pidofproc $pidfile $daemon > /dev/null || status="$?";
if [ "$status" = 0 ]; then
log_success_msg "$name is running";
return 0;
else
if [ "$status" = 4 ]; then
log_failure_msg "could not access PID file for $name";
return $status;
else
log_failure_msg "$name is not running";
return $status;
fi;
fi
}
Run Code Online (Sandbox Code Playgroud)
然而,将相同的函数调用插入到我自己制作的 init 脚本中会返回该函数未定义。所以它与 init 脚本的特殊性无关。它也不是之前在 init 脚本中声明的。我在网上读到它是 LSB 的一部分,但我不知道如何称呼它。有人可以帮我弄清楚如何使用这个奇妙的功能吗?
Rov*_*ion 19
我发现该函数来自/lib/lsb/init-functionsnginx init 脚本。所以补充:
. /lib/lsb/init-functions
Run Code Online (Sandbox Code Playgroud)
我的初始化脚本解决了这个问题。
| 归档时间: |
|
| 查看次数: |
12543 次 |
| 最近记录: |