From c9619397b6abfd2902ca417e130cb44adda53989 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 18 Jul 2022 19:39:01 +0200 Subject: [PATCH] Use current user's group for systemd files Generate systemd files using the current user's main group name instead of nogroup as the latter is not present in all systems. --- packages/create/create.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/create/create.js b/packages/create/create.js index 1d7972a2..bc826314 100755 --- a/packages/create/create.js +++ b/packages/create/create.js @@ -225,6 +225,17 @@ async function installClusterio(mode, plugins) { } } +async function groupIdToName(gid) { + try { + let exec = util.promisify(child_process.exec); + let { stdout } = await exec(`getent group ${gid}`); + return stdout.split(":")[0]; + } catch (err) { + logger.warn(`getent group ${gid} failed: ${err.message}`); + return gid; + } +} + async function writeScripts(mode) { if (["standalone", "master"].includes(mode)) { if (process.platform === "win32") { @@ -245,7 +256,7 @@ Description=Clusterio Master [Service] User=${os.userInfo().username} -Group=nogroup +Group=${await groupIdToName(os.userInfo().gid)} WorkingDirectory=${process.cwd()} KillMode=mixed KillSignal=SIGINT @@ -276,7 +287,7 @@ Description=Clusterio Slave [Service] User=${os.userInfo().username} -Group=nogroup +Group=${await groupIdToName(os.userInfo().gid)} WorkingDirectory=${process.cwd()} KillMode=mixed KillSignal=SIGINT