From f7b30939b58c682a3c24d18a342f7da825bc1ef1 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Wed, 13 Sep 2023 22:49:00 +0100 Subject: [PATCH] remove service-state when service exits --- devices/gl-ar750/default.nix | 1 - examples/arhcive.nix | 3 --- examples/extneder.nix | 3 --- examples/rotuer.nix | 3 --- pkgs/liminix-tools/services/default.nix | 15 +++++++++++---- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/devices/gl-ar750/default.nix b/devices/gl-ar750/default.nix index 94d34e4..79a6c30 100644 --- a/devices/gl-ar750/default.nix +++ b/devices/gl-ar750/default.nix @@ -75,7 +75,6 @@ dd if=/dev/$part of=data iflag=skip_bytes,fullblock bs=${toString size} skip=${toString offset} count=1 ) ''; - down = "true"; }; inherit (pkgs.pseudofile) dir symlink; inherit (pkgs.liminix.networking) interface; diff --git a/examples/arhcive.nix b/examples/arhcive.nix index 506b8bb..8e19594 100644 --- a/examples/arhcive.nix +++ b/examples/arhcive.nix @@ -84,9 +84,6 @@ in rec { done ) ''; - down = '' - rm -rf /run/service-state/${name}/ - ''; }; filesystem = dir { etc = dir { diff --git a/examples/extneder.nix b/examples/extneder.nix index 0e557ad..28697bd 100644 --- a/examples/extneder.nix +++ b/examples/extneder.nix @@ -119,9 +119,6 @@ in rec { done ) ''; - down = '' - rm -rf /run/service-state/${name}/ - ''; }; filesystem = dir { etc = dir { diff --git a/examples/rotuer.nix b/examples/rotuer.nix index 4a677b0..495a590 100644 --- a/examples/rotuer.nix +++ b/examples/rotuer.nix @@ -131,9 +131,6 @@ in rec { chmod 0444 resolv.conf ) ''; - down = '' - rm -rf /run/service-state/${name}/ - ''; }; filesystem = diff --git a/pkgs/liminix-tools/services/default.nix b/pkgs/liminix-tools/services/default.nix index 138e77e..60f4e9d 100644 --- a/pkgs/liminix-tools/services/default.nix +++ b/pkgs/liminix-tools/services/default.nix @@ -9,13 +9,18 @@ }: let inherit (builtins) concatStringsSep; - output = service: name: "/run/service-state/${service.name}/${name}"; + prefix = "/run/service-state"; + output = service: name: "${prefix}/${service.name}/${name}"; serviceScript = commands : '' #!/bin/sh exec 2>&1 . ${serviceFns} ${commands} ''; + cleanupScript = name : '' + #!/bin/sh + test -d ${prefix}/${name} && rm -rf ${prefix}/${name} + ''; service = { name , serviceType @@ -61,21 +66,23 @@ let in service (args // { buildInputs = [ logger ]; serviceType = "longrun"; - run = serviceScript run; + run = serviceScript "${run}\n${cleanupScript name}"; producer-for = "${name}-log"; }); oneshot = { name , up - , down + , down ? "" , outputs ? [] , dependencies ? [] , ... } @ args : service (args // { serviceType = "oneshot"; up = writeScript "${name}-up" (serviceScript up); - down= writeScript "${name}-down" (serviceScript down); + down = writeScript + "${name}-down" + "${serviceScript down}\n${cleanupScript name}"; }); bundle = { name