12

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 &
1
  • @Christopher I updated the question (not systemd) Jul 14, 2015 at 22:11

1 Answer 1

11

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
  • 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) Jul 15, 2015 at 12:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .