]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
initscripts: Implement storing PIDs in loadproc
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 11 Jan 2024 14:59:34 +0000 (15:59 +0100)
committerDaniel Weismüller <daniel.weismueller@ipfire.org>
Thu, 11 Jan 2024 14:59:34 +0000 (15:59 +0100)
Some programs do not write their own PID files any more, but since our
initscripts heavily rely on those, this extension allows to store it
easily.

Signed-off-by: Daniel Weismüller <daniel.weismueller@ipfire.org>
src/initscripts/system/functions

index e4cb304563f443589cb79b72998c151c894355dc..5a26aef45f843b55b95e628dbc93111a412b425f 100644 (file)
@@ -446,6 +446,7 @@ loadproc()
        local pidfile=""
        local forcestart=""
        local nicelevel=""
+       local pid
 
 # This will ensure compatibility with previous LFS Bootscripts
        if [ -n "${PIDFILE}" ]; then
@@ -521,12 +522,19 @@ loadproc()
                (
                        ${cmd} &>/dev/null
                ) &
+               pid="$!"
                evaluate_retval
        else
                ${cmd}
+               pid="$!"
                evaluate_retval # This is "Probably" not LSB compliant, but required to be compatible with older bootscripts
        fi
 
+       # Write the pidfile
+       if [ -n "${pid}" -a -n "${pidfile}" ]; then
+               echo "${pid}" > "${pidfile}"
+       fi
+
        return 0
 }