From 77e7c0538ab398a904e047c87620d1a6feb04708 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Fri, 22 Mar 2024 15:19:07 +0100 Subject: [PATCH] stages/systemd.unit.create: Environment and EnvironmentFile Support the Environment and EnvironmentFile options in the Service section of the unit file. The Environment option is set as an object with keys "key" and "value" and the key is validated with a pattern. Updated the stage to special-case the Environment option. --- stages/org.osbuild.systemd.unit.create | 3 +++ .../org.osbuild.systemd.unit.create.meta.json | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/stages/org.osbuild.systemd.unit.create b/stages/org.osbuild.systemd.unit.create index 3329da6e..38e7e18f 100755 --- a/stages/org.osbuild.systemd.unit.create +++ b/stages/org.osbuild.systemd.unit.create @@ -23,6 +23,9 @@ def main(tree, options): for option, value in opts.items(): if isinstance(value, list): for v in value: + if option == "Environment": + # Option value becomes "KEY=VALUE" (quoted) + v = '"' + v["key"] + "=" + str(v["value"]) + '"' config.set(section, str(option) + "=" + str(v)) else: config.set(section, option, str(value)) diff --git a/stages/org.osbuild.systemd.unit.create.meta.json b/stages/org.osbuild.systemd.unit.create.meta.json index adb652ac..d64d01ec 100644 --- a/stages/org.osbuild.systemd.unit.create.meta.json +++ b/stages/org.osbuild.systemd.unit.create.meta.json @@ -24,6 +24,8 @@ " - 'ExecStartPre' - [string]", " - 'ExecStopPost' - [string]", " - 'ExecStart' - [string]", + " - 'Environment' - [object]", + " - 'EnvironmentFile' - [string]", " - 'Install' section", " - 'WantedBy' - [string]", " - 'RequiredBy' - [string]" @@ -142,6 +144,31 @@ "items": { "type": "string" } + }, + "Environment": { + "type": "array", + "description": "Sets environment variables for executed process.", + "items": { + "type": "object", + "description": "Sets environment variables for executed process.", + "additionalProperties": false, + "properties": { + "key": { + "type": "string", + "pattern": "^[A-Za-z_][A-Za-z0-9_]*" + }, + "value": { + "type": "string" + } + } + } + }, + "EnvironmentFile": { + "type": "array", + "description": "Path to file that contains environment variables to set for the process.", + "items": { + "type": "string" + } } } },