From d64aeaa4fa0dc9d3f0f18d9af9ef18bf91c81138 Mon Sep 17 00:00:00 2001 From: Sebastian Tobie Date: Sat, 24 Feb 2024 11:33:30 +0100 Subject: [PATCH] added timer module --- CHANGELOG.rst | 10 ++- changelogs/changelog.yaml | 4 ++ galaxy.yml | 2 +- plugins/__init__.py | 0 plugins/modules/timer.py | 128 +++++++++++++++++++++++++++++++++++--- 5 files changed, 135 insertions(+), 9 deletions(-) delete mode 100644 plugins/__init__.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c6e1e1c..a1170e1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,10 +1,18 @@ ===================================== -sebastian.systemd 0.3.8 Release Notes +sebastian.systemd 0.4.0 Release Notes ===================================== .. contents:: Topics +v0.4.0 +====== + +Changelog +--------- + +added timer module + v0.3.8 ====== diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index 0df0628..daa392e 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -62,3 +62,7 @@ releases: changes: release_summary: fixed the import again. release_date: "2024-02-11" + 0.4.0: + release_date: "2024-02-24" + changes: + release_summary: added timer module diff --git a/galaxy.yml b/galaxy.yml index b20b3c6..60d61fc 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,7 +1,7 @@ --- namespace: sebastian name: systemd -version: 0.3.8 +version: 0.4.0 readme: README.md diff --git a/plugins/__init__.py b/plugins/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/plugins/modules/timer.py b/plugins/modules/timer.py index 15af16a..c0ba3f5 100644 --- a/plugins/modules/timer.py +++ b/plugins/modules/timer.py @@ -22,13 +22,49 @@ class Module(SystemdUnitModule, SystemdReloadMixin): # type: ignore argument_spec=dict( name=Types.str(required=True, help="Name of the unit"), description=Types.str(help="Description of the timer"), - onactive=Types.str(help="Starts the service x seconds after this timer was activated"), - onboot=Types.str(help="Starts the service x seconds after the device was booted or the container was started"), - onstartup=Types.str(help="Starts the service x seconds after the System's/User's systemd instance was started"), - onunitactive=Types.str(help="Starts the service x seconds after the unit this timer activates was last activated"), - onunitinactive=Types.str(help="Starts the service x seconds after the unit this timer activates was last deactivated"), - oncalendar=Types.str(help="Uses an Time string to start the unit."), - ) + onactive=Types.list( + help="Starts the service x seconds after this timer was activated", + elements=Types.str(), + ), + onboot=Types.list( + help="Starts the service x seconds after the device was booted or the container was started", + elements=Types.str(), + ), + onstartup=Types.list( + help="Starts the service x seconds after the System's/User's systemd instance was started", + elements=Types.str(), + ), + onunitactive=Types.list( + help="Starts the service x seconds after the unit this timer activates was last activated", + elements=Types.str(), + ), + onunitinactive=Types.list( + help="Starts the service x seconds after the unit this timer activates was last deactivated", + elements=Types.str(), + ), + oncalendar=Types.list( + help="Uses an Time string to start the unit.", + elements=Types.str(), + ), + persistent=Types.bool( + help="If the system was down in the time the timer would have started the unit, start the unit as soon as possible." + ), + randomdelay=Types.str(help="delays the activation by an random delay between 0 and the value"), + fixdelay=Types.bool( + help="set the random delay to an fixed value. It uses the timername, the user of the servicemanager and the machineid as the seed." + ), + unit=Types.str(help="The name of the unit. only needed if its not {{name}}.service"), + ), + required_one_of=[ + [ + "onactive", + "onboot", + "onstartup", + "onunitactive", + "onunitinactive", + "oncalendar", + ], + ], ) def prepare(self): @@ -37,6 +73,18 @@ class Module(SystemdUnitModule, SystemdReloadMixin): # type: ignore def body(self): section = "[Timer]\n" + params = [] + params.extend( + self.map_param( + onactive="OnActiveSec", + onboot="OnBootSec", + onstartup="OnStartupSec", + onunitactive="OnUnitActiveSec", + onunitinactive="OnUnitInactiveSec", + oncalendar="OnCalendar", + ), + ) + section += "".join(params) return section def unit(self) -> str: @@ -82,11 +130,61 @@ options: elements: str required: false type: list + fixdelay: + description: + - set the random delay to an fixed value. It uses the timername, the user of the + servicemanager and the machineid as the seed. + required: false + type: bool name: description: - Name of the unit required: true type: str + onactive: + default: [] + description: + - Starts the service x seconds after this timer was activated + elements: str + required: false + type: list + onboot: + default: [] + description: + - Starts the service x seconds after the device was booted or the container was + started + elements: str + required: false + type: list + oncalendar: + default: [] + description: + - Uses an Time string to start the unit. + elements: str + required: false + type: list + onstartup: + default: [] + description: + - Starts the service x seconds after the System's/User's systemd instance was + started + elements: str + required: false + type: list + onunitactive: + default: [] + description: + - Starts the service x seconds after the unit this timer activates was last activated + elements: str + required: false + type: list + onunitinactive: + default: [] + description: + - Starts the service x seconds after the unit this timer activates was last deactivated + elements: str + required: false + type: list partof: default: [] description: @@ -96,6 +194,17 @@ options: elements: str required: false type: list + persistent: + description: + - If the system was down in the time the timer would have started the unit, start + the unit as soon as possible. + required: false + type: bool + randomdelay: + description: + - delays the activation by an random delay between 0 and the value + required: false + type: str required_by: default: [] description: @@ -111,6 +220,11 @@ options: elements: str required: false type: list + unit: + description: + - The name of the unit. only needed if its not {{name}}.service + required: false + type: str wanted_by: default: [] description: