Linux RedHat daemon 功能使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21742227/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
RedHat daemon function usage
提问by quickshiftin
I'm working on an init script for Jetty on RHEL. Trying to use the daemon
function provided by the init library (/etc/rc.d/init.d/functions
).
我正在为 RHEL 上的 Jetty 编写一个初始化脚本。尝试使用daemon
init 库 ( /etc/rc.d/init.d/functions
)提供的函数。
I found this terse documentation, and an online example(I've also been looking at other init scripts on the system for examples).
我找到了这个简洁的文档和一个在线示例(我也一直在查看系统上的其他 init 脚本以获取示例)。
Look at this snippet from online to start the daemon
从网上看这个片段来启动守护进程
daemon --user="$DAEMON_USER" --pidfile="$PIDFILE" "$DAEMON $DAEMON_ARGS &"
RETVAL=$?
pid=`ps -A | grep $NAME | cut -d" " -f2`
pid=`echo $pid | cut -d" " -f2`
if [ -n "$pid" ]; then
echo $pid > "$PIDFILE"
fi
Why bother looking up the $PID
and writing it to the $PIDFILE
by hand? I guess I'm wondering what the point of the --pidfile
option to the daemon
function is.
为什么要费心查找$PID
并手写$PIDFILE
?我想我想知道--pidfile
该daemon
功能的选项有什么意义。
采纳答案by jnas
To answer the question you guess that you have, is that --pidfile
is used to check whether the daemon process is already running. On RHEL (and derivates) the daemon
function won't write the pidfile.
回答你猜你有的问题,--pidfile
是用来检查守护进程是否已经在运行。在 RHEL(和派生类)上,该daemon
函数不会写入 pidfile。
In the case that the program stays in the foreground it has to be explicitly sent to the background by appending &
to the command and the pid has to be fetched afterwards. $!
is not usable when using daemon
.
在程序停留在前台的情况下,它必须通过附加&
到命令显式发送到后台,然后必须获取 pid。$!
使用时不可用daemon
。