// Members of the 'terraria' group may start, stop and restart Terraria servers // (terraria@.service) without sudo. Nothing else: enable/disable and all // other units still need root. // // Starting a name that has no instance yet creates a vanilla instance with // default settings, as it does for root. // // Needs polkit 0.106 or newer (JavaScript rules); Ubuntu 22.04's 0.105 ignores it. polkit.addRule(function(action, subject) { if (action.id != "org.freedesktop.systemd1.manage-units" || !subject.isInGroup("terraria")) { return polkit.Result.NOT_HANDLED; } // Same names terractl accepts (valid_name) var unit = action.lookup("unit") || ""; var verb = action.lookup("verb") || ""; var verbs = ["start", "stop", "restart", "try-restart", "reset-failed"]; if (/^terraria@[A-Za-z0-9_][A-Za-z0-9_.-]*\.service$/.test(unit) && verbs.indexOf(verb) >= 0) { return polkit.Result.YES; } return polkit.Result.NOT_HANDLED; });