From 471c63b3998ab626abd80064b7961495fce9d6e3 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Mon, 13 May 2024 17:45:07 +0100 Subject: [PATCH] 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? --- pkgs/liminix-tools/services/builder.sh | 2 +- pkgs/liminix-tools/services/default.nix | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkgs/liminix-tools/services/builder.sh b/pkgs/liminix-tools/services/builder.sh index 5edfa5d..e163fe0 100644 --- a/pkgs/liminix-tools/services/builder.sh +++ b/pkgs/liminix-tools/services/builder.sh @@ -11,7 +11,7 @@ test -n "$contents" && for d in $contents; do touch $out/${name}/contents.d/$d 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) done diff --git a/pkgs/liminix-tools/services/default.nix b/pkgs/liminix-tools/services/default.nix index 34c9b7e..c0dbaf0 100644 --- a/pkgs/liminix-tools/services/default.nix +++ b/pkgs/liminix-tools/services/default.nix @@ -18,6 +18,7 @@ let ${commands} ''; cleanupScript = name : '' + #!/bin/sh if test -d ${prefix}/${name} ; then rm -rf ${prefix}/${name} ; fi ''; service = { @@ -26,6 +27,7 @@ let , run ? null , up ? null , down ? null + , finish ? null , outputs ? [] , notification-fd ? null , producer-for ? null @@ -41,7 +43,7 @@ let stdenvNoCC.mkDerivation { # we use stdenvNoCC to avoid generating derivations with names # 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; restart-on-upgrade = isTrigger; buildInputs = buildInputs ++ dependencies ++ contents; @@ -70,7 +72,8 @@ let in service (args // { buildInputs = buildInputs ++ [ logger ]; serviceType = "longrun"; - run = serviceScript "${run}\n${cleanupScript name}"; + run = serviceScript run; + finish = cleanupScript name; producer-for = "${name}-log"; });