11

I found lots of good documentation for ubuntu's start-stop-daemon and there is a man page for a binary daemon.

But from what I can tell the canonical way to start a daemon in a rhel/centos script is to source /etc/init.d/functions then use the daemon() function. But I can't find any good examples or documentation.

What is the canonical way to start a daemon in rhel/centos-6 init script?

my first attempt was:

#!/bin/bash
source /etc/init.d/functions
daemon --user USER nohup /path/to/your/binary arg1 arg2 >/dev/null 2>&1 &
  • @Christopher I updated the question (not systemd) – Trevor Boyd Smith Jul 14 '15 at 22:11
10

The documentation and example you are looking for is located at /usr/share/doc/initscripts-*/sysvinitfiles on CentOS/RHEL. Here is the documentation for the daemon function specifically:

daemon [ --check ] [ --user ] [+/-nicelevel] program [arguments] [&]

    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>

With CentOS/RHEL 6, you also have the option of using an upstart job file instead of writing a sysv init script.

  • 1
    This is exactly what I was looking for: 1. real documentation 2. guidance on whether I should add an & at the end of the line or not (there are other similar daemon commands that do the & background operation for you) – Trevor Boyd Smith Jul 15 '15 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.