stage/systemd-unit-create:paremeterize file location
User can now customize the systemd unit load path. User can select between etc or usr , defaults to 'usr'. Also user can customize the scope of the service between global or system, defaults to system. Signed-off-by: Sayan Paul <paul.sayan@gmail.com>
This commit is contained in:
parent
144b0563d6
commit
2d2cdd8097
4 changed files with 1105 additions and 54 deletions
|
|
@ -7,6 +7,8 @@ This stage allows to create Systemd unit files in
|
|||
'.service' file to be added. These names are validated using the
|
||||
same rules as specified by systemd.unit(5) and they must contain the
|
||||
'.service' suffix (other types of unit files are not supported).
|
||||
'unit-type' determines if the unit file is created at global or
|
||||
system level,'unit-path' will determine the systemd unit load path.
|
||||
|
||||
The Unit configuration can currently specify the following subset
|
||||
of options:
|
||||
|
|
@ -44,6 +46,18 @@ SCHEMA = r"""
|
|||
"type": "string",
|
||||
"pattern": "^[\\w:.\\\\-]+[@]{0,1}[\\w:.\\\\-]*\\.service$"
|
||||
},
|
||||
"unit-type": {
|
||||
"type": "string",
|
||||
"enum": ["system", "global"],
|
||||
"default": "system",
|
||||
"description": "Selects between systemd system or global unit to add dropin"
|
||||
},
|
||||
"unit-path": {
|
||||
"type": "string",
|
||||
"enum": ["usr", "etc"],
|
||||
"default": "usr",
|
||||
"description": "Define the system load path"
|
||||
},
|
||||
"config": {
|
||||
"additionalProperties": false,
|
||||
"type": "object",
|
||||
|
|
@ -167,8 +181,19 @@ def main(tree, options):
|
|||
config.set(section, str(option) + "=" + str(v))
|
||||
else:
|
||||
config.set(section, option, str(value))
|
||||
persistent = options.get("unit-path", "usr")
|
||||
systemd_dir = str()
|
||||
if persistent == "usr":
|
||||
systemd_dir = f"{tree}/usr/lib/systemd"
|
||||
elif persistent == "etc":
|
||||
systemd_dir = f"{tree}/etc/systemd"
|
||||
|
||||
unit_type = options.get("unit-type", "system")
|
||||
if unit_type == "system":
|
||||
systemd_dir += "/system"
|
||||
elif unit_type == "global":
|
||||
systemd_dir += "/user"
|
||||
|
||||
systemd_dir = f"{tree}/usr/lib/systemd/system"
|
||||
with open(f"{systemd_dir}/{filename}", "w", encoding="utf8") as f:
|
||||
config.write(f, space_around_delimiters=False)
|
||||
|
||||
|
|
|
|||
|
|
@ -616,6 +616,8 @@
|
|||
"type": "org.osbuild.systemd.unit.create",
|
||||
"options": {
|
||||
"filename": "create-directory.service",
|
||||
"unit-type": "global",
|
||||
"unit-path": "etc",
|
||||
"config": {
|
||||
"Unit": {
|
||||
"Description": "Create directory",
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"added_files": [
|
||||
"/usr/lib/systemd/system/create-directory.service"
|
||||
"/etc/systemd/user/create-directory.service"
|
||||
],
|
||||
"deleted_files": [],
|
||||
"differences": {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue