s6-rc do cleanup in "finish", don't append to "run" script

s6-supervise sends signals (e.g. SIGTERM) to the pid of the process
running "run", so how do we know if the ceanup commands are even
getting executed if the shell interpreter that is supposed to do that
got killed already?
This commit is contained in:
Daniel Barlow 2024-05-13 17:45:07 +01:00
parent 782feaeafa
commit 471c63b399
2 changed files with 6 additions and 3 deletions

View file

@ -11,7 +11,7 @@ test -n "$contents" && for d in $contents; do
touch $out/${name}/contents.d/$d touch $out/${name}/contents.d/$d
done done
for i in timeout-up timeout-down run notification-fd up down consumer-for producer-for pipeline-name restart-on-upgrade; do for i in timeout-up timeout-down run notification-fd up down finish consumer-for producer-for pipeline-name restart-on-upgrade; do
test -n "$(printenv $i)" && (echo "$(printenv $i)" > $out/${name}/$i) test -n "$(printenv $i)" && (echo "$(printenv $i)" > $out/${name}/$i)
done done

View file

@ -18,6 +18,7 @@ let
${commands} ${commands}
''; '';
cleanupScript = name : '' cleanupScript = name : ''
#!/bin/sh
if test -d ${prefix}/${name} ; then rm -rf ${prefix}/${name} ; fi if test -d ${prefix}/${name} ; then rm -rf ${prefix}/${name} ; fi
''; '';
service = { service = {
@ -26,6 +27,7 @@ let
, run ? null , run ? null
, up ? null , up ? null
, down ? null , down ? null
, finish ? null
, outputs ? [] , outputs ? []
, notification-fd ? null , notification-fd ? null
, producer-for ? null , producer-for ? null
@ -41,7 +43,7 @@ let
stdenvNoCC.mkDerivation { stdenvNoCC.mkDerivation {
# we use stdenvNoCC to avoid generating derivations with names # we use stdenvNoCC to avoid generating derivations with names
# like foo.service-mips-linux-musl # like foo.service-mips-linux-musl
inherit name serviceType up down run notification-fd inherit name serviceType up down run finish notification-fd
producer-for consumer-for pipeline-name timeout-up timeout-down; producer-for consumer-for pipeline-name timeout-up timeout-down;
restart-on-upgrade = isTrigger; restart-on-upgrade = isTrigger;
buildInputs = buildInputs ++ dependencies ++ contents; buildInputs = buildInputs ++ dependencies ++ contents;
@ -70,7 +72,8 @@ let
in service (args // { in service (args // {
buildInputs = buildInputs ++ [ logger ]; buildInputs = buildInputs ++ [ logger ];
serviceType = "longrun"; serviceType = "longrun";
run = serviceScript "${run}\n${cleanupScript name}"; run = serviceScript run;
finish = cleanupScript name;
producer-for = "${name}-log"; producer-for = "${name}-log";
}); });