]> granicus.if.org Git - icinga2/commit
Fix logging under systemd 6356/head
authorAlan Jenkins <alan.christopher.jenkins@gmail.com>
Tue, 29 May 2018 16:24:05 +0000 (17:24 +0100)
committerAlan Jenkins <alan.christopher.jenkins@gmail.com>
Sat, 25 Aug 2018 09:21:06 +0000 (10:21 +0100)
commita21166dcf8290eb21a5eeca3e8449ae09d7775f2
treeeccc937951a16ddab96429c0022011913f54e57e
parent50463a6a10ea1d1295758e0c8489c28f78b66eab
Fix logging under systemd

icinga2.service used `-e ${ICINGA2_ERROR_LOG}`, but this is documented
as having no effect without `-d`.  Furthermore, icinga2 under systemd
unconditionally logged everything to the system log (but without setting
the log level etc), which contradicted the documentation.  (Issue #6339)

Stop icinga2 on systemd from logging to stdout - and hence the system log -
once it has finished starting up.  Just like when you start icinga2 from a
terminal using `-d`.  And just like -d, we stop logging fatal errors to
stderr, and instead write to the log file passed with `-e`.

As per docs, mainlog (icinga2.log) is already enabled by default.  And
pre-startup messages including config errors will still appear in the
system log.

This uses a new option --close-stdio, which has the same effect on logging as
--daemonize, but does not fork or call setsid().

For this purpose, I moved setsid() up and into Daemonize().

Consequence of that last point: if anyone is weird enough to specify a TTY
device file as the fatal error log (-e option), that will become icinga's
controlling terminal, which you generally don't want as a daemon.  This
makes it consistent with the existing behaviour for icinga mainlog.  For
this reason you're supposed to use O_NOCTTY in Linux daemons.  But I wasn't
sure where icinga would want to put the ugly `#ifdef _WIN32 ... #else ...`.
doc/11-cli-commands.md
etc/initsystem/icinga2.service.cmake
lib/cli/daemoncommand.cpp