Synit: depend-on initialization scripts

This commit is contained in:
Emery Hemingway 2023-11-25 21:05:42 +02:00
parent 7b19ca3492
commit 42bd83603c
4 changed files with 23 additions and 6 deletions

View File

@ -1,7 +1,9 @@
{ lib, writeTextFile, toPreserves }:
{ lib, runtimeShell, toPreserves, writeScript, writeTextFile }:
{ name, description, argv, environment, directory
# List of services that this configuration depends on.
# Shell instructions that specify how the state of the process should be initialized.
, initialize ? ""
# List of services that this configuration depends on.
, dependencies ? [ ]
# Daemon will not be started until all elements of depends-on are asserted.
# Example: [ "<service-state <milestone network> up>" ]
@ -39,6 +41,21 @@ in writeTextFile {
<depends-on ${serviceName} ${pkg.serviceName}>
'') dependencies)
+ (lib.strings.optionalString (initialize != "") (let
# TODO: depend the initialization on other dependencies?
initializeName = "initialize-${name}";
script = writeScript "${initializeName}.sh" ''
#!${runtimeShell}
${initialize}
'';
in ''
<depends-on ${serviceName} <service-state <daemon ${initializeName}> complete>>
<deamon ${initializeName} {
argv: [ "${script}" ]
restart: on-error
}>
''))
+ ''
<daemon ${name} ${toPreserves processSpec}>
'';

View File

@ -1,4 +1,4 @@
{ lib, undaemonize, writeTextFile }:
{ lib, runtimeShell, writeScript, writeTextFile, undaemonize }:
rec {
util = import ./util.nix { inherit lib; };
@ -6,7 +6,7 @@ rec {
toPreserves = util.toPreserves { };
createSynitDaemon = import ../../backends/synit/create-synit-daemon.nix {
inherit lib writeTextFile;
inherit lib runtimeShell writeScript writeTextFile;
inherit toPreserves;
};

View File

@ -6,7 +6,7 @@
let
generatedTargetSpecificArgs = {
inherit name description environment directory dependencies;
inherit name description environment directory dependencies initialize;
argv = if foregroundProcess != null then
[ foregroundProcess ] ++ foregroundProcessArgs

View File

@ -115,7 +115,7 @@ let
};
synit = import ../../backends/synit {
inherit (pkgs) lib undaemonize writeTextFile;
inherit (pkgs) lib runtimeShell undaemonize writeScript writeTextFile;
};
in