Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

5 Answers 5

up vote 5 down vote accepted

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).

share|improve this answer
    
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. –  flyer88 Jan 3 '12 at 16:49

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.

share|improve this answer

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.

share|improve this answer

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|improve this answer

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/*.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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