How can I run a daemon with custom parameters

15,617

Solution 1

Guessing from the Gentoo Wiki, editing NTPD_OPTS in /etc/conf.d/ntpd probably does the trick (regardless of the question if -g is advisable, no idea).

Solution 2

In Debian and Ubuntu, often daemon have some configuration parameters set in /etc/default/daemon-name, this is e.g. /etc/default/ntp:

NTPD_OPTS='-g'

This file is sourced from /etc/init.d/ntp, and the value of the corresponding variables used opportunely:

# near the beginning

if [ -r /etc/default/ntp ]; then
    . /etc/default/ntp
fi

# later

start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON \
    -- -p $PIDFILE $NTPD_OPTS

I don't know if Gentoo has something similar.

Solution 3

Different distributions do it differently. Generally speaking, search under /etc for the place where that specific daemon is started (grep -r ntpd /etc or find /etc -type f -exec grep ntpd {} +), then see how the script that starts it gets its parameters. Alternatively, consult your distribution's documentation for general principles.

Usually, either there is a large shell script or other configuration file that starts many services, or there is one script or configuration file for each service. The parameters may be given in that script or obtained from a variable that is set in some other configuration file. Common locations include /etc/init*, /etc/rc* and /etc/default/*.

Solution 4

Daemon is like any other program written from source code and compiled into executable format, it can be made to accept arguments, process the arguments such as to use them as argument specifying switches or arguments themselves. The difference between daemon and program can be in essence that daemon mode of the program is switching the tasks into background mode and optionally depending the requirement of the service, is to listen on the network interface and accept requests over wire. So passing the arguments from the command line on shell prompt or right after specifying the path of the daemon executable in the script is same. The method of configurations or variables that are used in shell script to invoke the daemon with necessary arguments however might differ across in style or convention. It is important to read the manual, if it is provided, to know which arguments are accepted by the daemon executable or the program and know what are they used before putting them to use in the execution than just providing the options.

Solution 5

I am moving between many Linux distributions and versions. The generic way - which I take in these cases is:

Read the init-script - it often sources one ore more configuration files. If the init-script does not parse any configuration file you can modify the init-script. The drawback is that an update of the package the init-script belongs to will overwrite your changes.

Share:
15,617

Related videos on Youtube

flyer88
Author by

flyer88

Updated on September 18, 2022

Comments

  • flyer88
    flyer88 almost 2 years

    I am wondering how I can run a daemon, in this case NTP, with custom parameters.

    For example in my Ubuntu PC I observe that I've got ntpd running this way:

    $ ps aux | grep ntpd
    ntp  5936  ...  0:00 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 119:127
    

    You may notice that -g parameter.

    But in my Gentoo PC I run the same command and I can observe that the ntp daemon is not running with that -g parameter and I want to add it!

    Is this a distribution specific issue? How can I handle this?

  • flyer88
    flyer88 over 12 years
    Thanks! That should work. However I was looking a more generic solution (if it exists) Maybhe I should read more about daemons and how they are managed in general.