0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-14 06:00:33 +03:00

Merge pull request #85428 from serokell/kirelagin/unit-script-name

systemd: Simplify unit script names
This commit is contained in:
Linus Heckemann 2020-05-12 09:35:26 +02:00 committed by GitHub
commit 90c0191735
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -201,8 +201,23 @@ let
]; ];
makeJobScript = name: text: makeJobScript = name: text:
let mkScriptName = s: "unit-script-" + (replaceChars [ "\\" "@" ] [ "-" "_" ] (shellEscape s) ); let
in pkgs.writeTextFile { name = mkScriptName name; executable = true; inherit text; }; scriptName = replaceChars [ "\\" "@" ] [ "-" "_" ] (shellEscape name);
out = pkgs.writeTextFile {
# The derivation name is different from the script file name
# to keep the script file name short to avoid cluttering logs.
name = "unit-script-${scriptName}";
executable = true;
destination = "/bin/${scriptName}";
text = ''
#!${pkgs.runtimeShell} -e
${text}
'';
checkPhase = ''
${pkgs.stdenv.shell} -n "$out/bin/${scriptName}"
'';
};
in "${out}/bin/${scriptName}";
unitConfig = { config, options, ... }: { unitConfig = { config, options, ... }: {
config = { config = {
@ -250,40 +265,28 @@ let
environment.PATH = config.path; environment.PATH = config.path;
} }
(mkIf (config.preStart != "") (mkIf (config.preStart != "")
{ serviceConfig.ExecStartPre = makeJobScript "${name}-pre-start" '' { serviceConfig.ExecStartPre =
#! ${pkgs.runtimeShell} -e makeJobScript "${name}-pre-start" config.preStart;
${config.preStart}
'';
}) })
(mkIf (config.script != "") (mkIf (config.script != "")
{ serviceConfig.ExecStart = makeJobScript "${name}-start" '' { serviceConfig.ExecStart =
#! ${pkgs.runtimeShell} -e makeJobScript "${name}-start" config.script + " " + config.scriptArgs;
${config.script}
'' + " " + config.scriptArgs;
}) })
(mkIf (config.postStart != "") (mkIf (config.postStart != "")
{ serviceConfig.ExecStartPost = makeJobScript "${name}-post-start" '' { serviceConfig.ExecStartPost =
#! ${pkgs.runtimeShell} -e makeJobScript "${name}-post-start" config.postStart;
${config.postStart}
'';
}) })
(mkIf (config.reload != "") (mkIf (config.reload != "")
{ serviceConfig.ExecReload = makeJobScript "${name}-reload" '' { serviceConfig.ExecReload =
#! ${pkgs.runtimeShell} -e makeJobScript "${name}-reload" config.reload;
${config.reload}
'';
}) })
(mkIf (config.preStop != "") (mkIf (config.preStop != "")
{ serviceConfig.ExecStop = makeJobScript "${name}-pre-stop" '' { serviceConfig.ExecStop =
#! ${pkgs.runtimeShell} -e makeJobScript "${name}-pre-stop" config.preStop;
${config.preStop}
'';
}) })
(mkIf (config.postStop != "") (mkIf (config.postStop != "")
{ serviceConfig.ExecStopPost = makeJobScript "${name}-post-stop" '' { serviceConfig.ExecStopPost =
#! ${pkgs.runtimeShell} -e makeJobScript "${name}-post-stop" config.postStop;
${config.postStop}
'';
}) })
]; ];
}; };