在 rhel/centos-6 init 脚本中启动守护进程的规范方式是什么?

Tre*_*ith 11 rhel centos init-script init

我找到了很多关于 ubuntu 的 start-stop-daemon 的好文档,并且有一个二进制文件的手册页daemon

但是据我所知,在 rhel/centos 脚本中启动守护程序的规范方法是源代码/etc/init.d/functions然后使用该daemon()函数。但我找不到任何好的例子或文档。

在 rhel/centos-6 init 脚本中启动守护进程的规范方法是什么?

我的第一次尝试是:

#!/bin/bash
source /etc/init.d/functions
daemon --user USER nohup /path/to/your/binary arg1 arg2 >/dev/null 2>&1 &
Run Code Online (Sandbox Code Playgroud)

jor*_*anm 10

您正在寻找的文档和示例位于/usr/share/doc/initscripts-*/sysvinitfilesCentOS/RHEL。以下是该daemon功能的文档:

守护进程 [ --check ] [ --user ] [+/-nicelevel] 程序 [参数] [&]

    Starts a daemon, if it is not already running.  Does
    other useful things like keeping the daemon from dumping
    core if it terminates unexpectedly.

    --check <name>:
       Check that <name> is running, as opposed to simply the
       first argument passed to daemon().
    --user <username>:
       Run command as user <username>
Run Code Online (Sandbox Code Playgroud)

在 CentOS/RHEL 6 中,您还可以选择使用 upstart 作业文件,而不是编写 sysv init 脚本。