From 3c950704e1cc430cf36db88cebf9bdf8780f9cb1 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 13 Feb 2024 21:41:43 +0000 Subject: [PATCH] rename /run/service-state to /run/services/outputs --- NEWS | 21 +++++++++++++++++++++ modules/dhcp6c/address.nix | 2 +- modules/dhcp6c/client.nix | 2 +- modules/dhcp6c/prefix.nix | 2 +- modules/s6/scripts/rc.init | 11 +++++++++-- pkgs/liminix-tools/services/builder.sh | 2 +- pkgs/liminix-tools/services/default.nix | 2 +- pkgs/service-fns/default.nix | 9 ++++++++- 8 files changed, 43 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index a43c537..4169d82 100644 --- a/NEWS +++ b/NEWS @@ -48,4 +48,25 @@ them afterwards as though they were "out of tree". Refer to commit b9c0d93670275e69df24902b05bf4aa4f0fcbe96 for a fuller explanation of how this simplifies things. +2024-02-13 + +So that we can be more consistent about services that would like their +state to be preserved across boots (assuming a writable filesystem) +these changes have been made + +* /run/service-state has been moved to /run/services/outputs + to better reflect what it's used for +* /run/services/state is either a symlink to /persist/services/state + (if there's a writeable fs on /persist) or a directory (if there + isn't) + +The `output` and `mkoutputs` functions defined by ${serviceFns} +have been updated, so unless your services are hardcoding service-state +then the change should be seamless + + + + + +21:02:51 GMT 2024 diff --git a/modules/dhcp6c/address.nix b/modules/dhcp6c/address.nix index a00eeb4..6c97003 100644 --- a/modules/dhcp6c/address.nix +++ b/modules/dhcp6c/address.nix @@ -11,6 +11,6 @@ let script = callPackage ./acquire-wan-address.nix { }; in longrun { inherit name; - run = "${script} /run/service-state/${client.name} $(output ${interface} ifname)"; + run = "${script} $SERVICE_OUTPUTS/${client.name} $(output ${interface} ifname)"; dependencies = [ client interface ]; } diff --git a/modules/dhcp6c/client.nix b/modules/dhcp6c/client.nix index 5c6a765..fb662c5 100644 --- a/modules/dhcp6c/client.nix +++ b/modules/dhcp6c/client.nix @@ -13,7 +13,7 @@ in longrun { inherit name; notification-fd = 10; run = '' - export SERVICE_STATE=/run/service-state/${name} + export SERVICE_STATE=$SERVICE_OUTPUTS/${name} ${odhcp6c}/bin/odhcp6c -s ${odhcp-script} -e -v -p /run/${name}.pid -P0 $(output ${interface} ifname) ) ''; diff --git a/modules/dhcp6c/prefix.nix b/modules/dhcp6c/prefix.nix index b43da66..2848e5d 100644 --- a/modules/dhcp6c/prefix.nix +++ b/modules/dhcp6c/prefix.nix @@ -11,6 +11,6 @@ let script = callPackage ./acquire-delegated-prefix.nix { }; in longrun { inherit name; - run = "${script} /run/service-state/${client.name} $(output ${interface} ifname)"; + run = "${script} $SERVICE_OUTPUTS/${client.name} $(output ${interface} ifname)"; dependencies = [ client interface ]; } diff --git a/modules/s6/scripts/rc.init b/modules/s6/scripts/rc.init index 7b5bfd1..b1860e4 100755 --- a/modules/s6/scripts/rc.init +++ b/modules/s6/scripts/rc.init @@ -22,8 +22,15 @@ mount -t tmpfs none /tmp mkdir /dev/pts mount -t devpts none /dev/pts -mkdir -m 0751 /run/service-state -chgrp system /run/service-state +mkdir -m 0751 -p /run/services/outputs +chgrp system /run/services/outputs + +if test -d /persist; then + mkdir -m 0751 -p /persist/services/state + (cd /run/services && ln -s ../../persist/services/state .) +else + mkdir -m 0751 -p /run/services/state +fi ### If your services are managed by s6-rc: ### (replace /run/service with your scandir) diff --git a/pkgs/liminix-tools/services/builder.sh b/pkgs/liminix-tools/services/builder.sh index 5709d4a..a0b6778 100644 --- a/pkgs/liminix-tools/services/builder.sh +++ b/pkgs/liminix-tools/services/builder.sh @@ -15,6 +15,6 @@ for i in run notification-fd up down consumer-for producer-for pipeline-name ; d test -n "$(printenv $i)" && (echo "$(printenv $i)" > $out/${name}/$i) done -( cd $out && ln -s /run/service-state/${name} ./.outputs ) +( cd $out && ln -s /run/services/outputs/${name} ./.outputs ) for i in $out/${name}/{down,up,run} ; do test -f $i && chmod +x $i; done true diff --git a/pkgs/liminix-tools/services/default.nix b/pkgs/liminix-tools/services/default.nix index 7356d33..d851cd9 100644 --- a/pkgs/liminix-tools/services/default.nix +++ b/pkgs/liminix-tools/services/default.nix @@ -9,7 +9,7 @@ }: let inherit (builtins) concatStringsSep; - prefix = "/run/service-state"; + prefix = "/run/services/outputs"; output = service: name: "${prefix}/${service.name}/${name}"; serviceScript = commands : '' #!/bin/sh diff --git a/pkgs/service-fns/default.nix b/pkgs/service-fns/default.nix index c16c44c..1966396 100644 --- a/pkgs/service-fns/default.nix +++ b/pkgs/service-fns/default.nix @@ -2,8 +2,15 @@ writeText "service-fns.sh" '' output() { cat $1/.outputs/$2; } output_path() { echo $(realpath $1/.outputs)/$2; } + SERVICE_OUTPUTS=/run/services/outputs + SERVICE_STATE=/run/services/state mkoutputs() { - d=/run/service-state/$1 + d=$SERVICE_OUTPUTS/$1 + mkdir -m 2751 -p $d && chown root:system $d + echo $d + } + mkstate() { + d=$SERVICE_STATE/$1 mkdir -m 2751 -p $d && chown root:system $d echo $d }