]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Make pidfile env-overridable, empty disables it
authorVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 29 May 2026 07:43:53 +0000 (08:43 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 29 May 2026 08:04:15 +0000 (09:04 +0100)
Template the baseline pidfile so deployments can relocate or disable it
without patching conf/rspamd.conf:

    pidfile = "{= env.PIDFILE|default('$RUNDIR/rspamd.pid') =}";

With no RSPAMD_PIDFILE set it renders to the previous default
($RUNDIR/rspamd.pid). An empty RSPAMD_PIDFILE renders an empty string,
which now means "do not write a pidfile" -- useful when running as PID 1
in a container. Extend the existing cfg->pid_file == NULL guards in both
rspamd_write_pid() and main() to also treat an empty string as unset, so
the existing "pid file is not specified" path is taken.

conf/rspamd.conf
src/rspamd.c

index 97bbdf5b4186714550799cabd7954a6d4b507dac..0b6448072d7f47336d0bbece63f408d79afe9efd 100644 (file)
@@ -18,7 +18,9 @@
 .include "$CONFDIR/common.conf"
 
 options {
-    pidfile = "$RUNDIR/rspamd.pid";
+    # An empty RSPAMD_PIDFILE disables writing a pidfile (useful when running
+    # as PID 1); otherwise it overrides the default location.
+    pidfile = "{= env.PIDFILE|default('$RUNDIR/rspamd.pid') =}";
     .include "$CONFDIR/options.inc"
     .include(try=true; priority=1,duplicate=merge) "$LOCAL_CONFDIR/local.d/options.inc"
     .include(try=true; priority=10) "$LOCAL_CONFDIR/override.d/options.inc"
index 210770752deaeb168a58e1e24af6e9274fe98195..8c5b874c7419e39acc98d8bd6e3e3b4411906d89 100644 (file)
@@ -223,7 +223,7 @@ rspamd_write_pid(struct rspamd_main *main)
 {
        pid_t pid;
 
-       if (main->cfg->pid_file == NULL) {
+       if (main->cfg->pid_file == NULL || main->cfg->pid_file[0] == '\0') {
                return -1;
        }
        main->pfh = rspamd_pidfile_open(main->cfg->pid_file, 0644, &pid);
@@ -1621,7 +1621,8 @@ int main(int argc, char **argv, char **env)
        sigpipe_act.sa_flags = 0;
        sigaction(SIGPIPE, &sigpipe_act, NULL);
 
-       if (rspamd_main->cfg->pid_file == NULL) {
+       if (rspamd_main->cfg->pid_file == NULL ||
+               rspamd_main->cfg->pid_file[0] == '\0') {
                msg_info_main("pid file is not specified, skipping writing it");
                skip_pid = TRUE;
        }