Skip to content

Changed conflicting supervise-daemon pid filename

Noah Zalev requested to merge noah24/aports:master into master

When Monit is invoked by the root user, and the PID location is not specifically set in the config (which it is not by default), it uses /run/monit.pid.

#define MYPIDDIR           PIDDIR
#define MYPIDFILE          "monit.pid"

...

/* Set the location of this programs pidfile */
if (! getuid()) {
        snprintf(pidfile, STRLEN, "%s/%s", MYPIDDIR, MYPIDFILE);
} else { 

Where PIDDIR is set in configure.ac as /run.

An issue arises where the Monit daemon and supervise-daemon are using the same PID file: /run/monit.pid. monit.initd sets it as follows:

pidfile="/run/$RC_SVCNAME.pid"

This tricks Monit into believing there is already an instance running. In this case, the behaviour that Monit will take is to attempt to awaken the existing Monit instance and quit.

/**
 * Wakeup a sleeping monit daemon.
 * Returns true on success otherwise false
 */
bool do_wakeupcall(void) {
        pid_t pid;

        if ((pid = exist_daemon()) > 0) {
                kill(pid, SIGUSR1);
                Log_info("Monit daemon with PID %d awakened\n", pid);

                return true;
        }

        return false;
}


...


    if (do_wakeupcall())
            exit(0);

The end result is that we see supervise-daemon repeatedly try to restart Monit, where Monit repeatedly exits.

Dec 18 16:13:10 dc2 daemon.info supervise-daemon[28449]: Supervisor command line: supervise-daemon monit --start --pidfile /run/monit.pid --respawn-delay 2 --respawn-max 5 --respawn-period 1800 /usr/bin/monit -- -c /etc/monitrc -I 
Dec 18 16:13:10 dc2 daemon.info supervise-daemon[28452]: Child command line: /usr/bin/monit -c /etc/monitrc -I 
Dec 18 16:13:10 dc2 user.info monit[28452]: Monit daemon with PID 28450 awakened
Dec 18 16:13:10 dc2 daemon.warn supervise-daemon[28450]: /usr/bin/monit, pid 28452, exited with return code 0
Dec 18 16:13:12 dc2 daemon.info supervise-daemon[28457]: Child command line: /usr/bin/monit -c /etc/monitrc -I 
Dec 18 16:13:12 dc2 user.info monit[28457]: Monit daemon with PID 28450 awakened
Dec 18 16:13:12 dc2 daemon.warn supervise-daemon[28450]: /usr/bin/monit, pid 28457, exited with return code 0
Dec 18 16:13:14 dc2 daemon.info supervise-daemon[28458]: Child command line: /usr/bin/monit -c /etc/monitrc -I 
Dec 18 16:13:14 dc2 user.info monit[28458]: Monit daemon with PID 28450 awakened
Dec 18 16:13:14 dc2 daemon.warn supervise-daemon[28450]: /usr/bin/monit, pid 28458, exited with return code 0
Dec 18 16:13:16 dc2 daemon.info supervise-daemon[28460]: Child command line: /usr/bin/monit -c /etc/monitrc -I 
Dec 18 16:13:16 dc2 user.info monit[28460]: Monit daemon with PID 28450 awakened
Dec 18 16:13:16 dc2 daemon.warn supervise-daemon[28450]: /usr/bin/monit, pid 28460, exited with return code 0
Dec 18 16:13:18 dc2 daemon.info supervise-daemon[28461]: Child command line: /usr/bin/monit -c /etc/monitrc -I 
Dec 18 16:13:18 dc2 user.info monit[28461]: Monit daemon with PID 28450 awakened
Dec 18 16:13:18 dc2 daemon.warn supervise-daemon[28450]: /usr/bin/monit, pid 28461, exited with return code 0
Dec 18 16:13:20 dc2 daemon.info supervise-daemon[28462]: Child command line: /usr/bin/monit -c /etc/monitrc -I 
Dec 18 16:13:20 dc2 user.info monit[28462]: Monit daemon with PID 28450 awakened
Dec 18 16:13:20 dc2 daemon.warn supervise-daemon[28450]: /usr/bin/monit, pid 28462, exited with return code 0
Dec 18 16:13:20 dc2 daemon.warn supervise-daemon[28450]: respawned "/usr/bin/monit" too many times, exiting

This patch resolves this behaviour by changing supervise-daemon's pid file from /run/monit.pid to /run/_monit.pid, such that the two no longer overlap.

This issue was introduced on 2023-12-06 in 04082d8e. The default installation of Monit can no longer start using the service.

Merge request reports