Patch for nsd using hardcoded name "nsd"

Hi,

I am using two nsd instances to run two different nameservers on the
same machine. Since both need to have proper initscript support, I
have made a hardlink under a different name to /usr/sbin/nsd, and
initscripts can use my new name "nsdhm", and do things like "pidof nsdhm".

I got very confused when my i saw "nsd" started to fail, and it took
me a while to figure out it was my nsdhm that had failed to start.

Attached patch changes some of the log entries to use argv[0] instead
of the string "nsd" for logging.

Paul

(attachments)

nsd-processname.patch (1020 Bytes)

That's a very good idea!

Assuming the final pathname in argv[0] is sufficient for differentiation
in the logs, this expression will provide the appropriate pointer to
just that final pathname component:

    char *argv0 = (argv0 = strrchr(argv[0], '/')) ? argv0 + 1 : argv[0];

Paul Wouters schreef:

Hi,

I am using two nsd instances to run two different nameservers on the
same machine. Since both need to have proper initscript support, I
have made a hardlink under a different name to /usr/sbin/nsd, and
initscripts can use my new name "nsdhm", and do things like "pidof nsdhm".

I got very confused when my i saw "nsd" started to fail, and it took
me a while to figure out it was my nsdhm that had failed to start.

Attached patch changes some of the log entries to use argv[0] instead
of the string "nsd" for logging.

Paul

Wouldn't it be much easier and cleaner to make both instances write to a
separate logfile, /var/log/nsd vs /var/log/nsdhm (or whatever you're
preferred name would be)?

There are many (linux) distributions that support multiple instances of
the same server (with multiple config files) out of the box in their
init scripts.

That's not possible when using something like syslog.

Ideally there could be a configuration item that would allow one to
specify the "ident" value passed to openlog(3), with the default being
argv0. I guess there would have to be one per sub-program too.

Wouldn't it be much easier and cleaner to make both instances write to a
separate logfile, /var/log/nsd vs /var/log/nsdhm (or whatever you're
preferred name would be)?

The logging was not really my problem. It just caused confusion for me
since both instances are setup to use syslog, and I expected one to be
called "nsd" and the other "nsdhm".

There are many (linux) distributions that support multiple instances of
the same server (with multiple config files) out of the box in their
init scripts.

Mostly, the problem is with stale pid files, and the use of "pidof" to
determine if a certain instance is still running. Having different
names makes them fully independant of each other.

Paul

Indeed PID files are another issue that must be dealt with when running
multiple instances of a daemon on the same host (especially without
chroot or equivalent).

It would be nice if the daemon automatically chose unique identifiers
for each instance, and if argv[0], or especially the final pathname
component of argv[0], is usually made to be unique for purposes of
starting each instance then this value would be a good default choice
for the unique identifier, at least for some sites.

However I remember now that in the production environments I've designed
in the past the ideal mechanism to run multiple instances of a daemon is
a simple wrapper script (eg. copies of the BSD /etc/rc.d script) that
invoke each instance with a unique set of command-line parameters
(eg. separate config files, etc. -- whatever else is necessary). Thus
argv[0] will be identical for both instances and so it falls back to
having the unique identifier optionally be specified as a configuration
item (command-line parameter or config file entry, etc.).

As a only barely related side note in relation to newsyslog I will also
mention the multiple PID file issue for daemons where each instance
writes to the same log file. In the ToDo notes for the version of
newsyslog I maintain I've made the following comments and questions:

- what happens, or should happen, if/when there are multiple PIDs in a
  pidfile?

- consider supporting the specification of multiple pidfiles for a given
  log for the case where multiple long-running daemons write to the same
  logfile, eg. as:

  /var/run/named-outside.pid,/var/run/named-inside.pid

  Or teach people to either use a proper syslog daemon instead of
  allowing/configuring their daemons to write directly to any log files,
  or else teach them to always use separate log files for each instance!