fix(minecraft-fabric): avoid unset CREDENTIALS_DIRECTORY in ExecStop

For mystifying reasons, Type=simple and CREDENTIALS_DIRECTORY in
ExecStop have stopped working (when exactly I don't know, but presumably
256). Apparently, you are supposed to use Type=exec with credentials due
to raciness (I've personally never experienced):
<https://github.com/systemd/systemd/issues/32583>.

Just changing the type did not resolve the issue of
CREDENTIALS_DIRECTORY being unset, though. It appears, though, that the
issue is merely an unset environment variable and not the credentials
being unavailable: We can work around the problem by setting an
appropriate environment variable ourselves.

Change-Id: Ifcdb1f3bce782ea1c568a9bc413f3fb29f0985c5
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12649
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Autosubmit: sterni <sternenseemann@systemli.org>
This commit is contained in:
sterni 2024-10-17 18:38:48 +02:00 committed by clbot
parent 0814eda06b
commit 6501ee194b

View file

@ -273,7 +273,7 @@ let
export MCRCON_HOST=localhost
export MCRCON_PORT=${lib.escapeShellArg instanceCfg.serverProperties."rcon.port"}
# Unfortunately, mcrcon can't read the password from a file
export MCRCON_PASS="$(cat "''${CREDENTIALS_DIRECTORY}/rcon-password")"
export MCRCON_PASS="$(cat "''${RCON_PASSWORD}")"
# Send stop request
"${bins.mcrcon}" 'say Server is stopping' save-all stop
@ -314,7 +314,7 @@ let
# Create config and set password from credentials (echo hopefully doesn't leak)
copyFromStore "${serverPropertiesFile name instanceCfg}" server.properties
echo "rcon.password=$(cat "$CREDENTIALS_DIRECTORY/rcon-password")" >> server.properties
echo "rcon.password=$(cat "$RCON_PASSWORD")" >> server.properties
# Build patched jar
"${bins.java}" -jar "${fabricInstallerJar}" \
@ -509,8 +509,13 @@ in
after = [ "network.target" ];
inherit (instanceCfg) enable;
environment = {
# Workaround for https://github.com/systemd/systemd/issues/34805
"RCON_PASSWORD" = "%d/rcon-password";
};
serviceConfig = {
Type = "simple";
Type = "exec";
User = instanceCfg.user;
Group = instanceCfg.group;
ExecStart = startScript name instanceCfg;