From 0fd1093dcdbe0285f7c39703c414196650e890a2 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 4 Jan 2024 11:40:39 +0100 Subject: [PATCH] Created role for systemd timers --- roles/systemd-timer/handlers/main.yml | 6 ++++++ roles/systemd-timer/tasks/main.yml | 7 +++++++ roles/systemd-timer/templates/dummy.timer.j2 | 10 ++++++++++ 3 files changed, 23 insertions(+) create mode 100644 roles/systemd-timer/handlers/main.yml create mode 100644 roles/systemd-timer/tasks/main.yml create mode 100644 roles/systemd-timer/templates/dummy.timer.j2 diff --git a/roles/systemd-timer/handlers/main.yml b/roles/systemd-timer/handlers/main.yml new file mode 100644 index 00000000..0daa96bd --- /dev/null +++ b/roles/systemd-timer/handlers/main.yml @@ -0,0 +1,6 @@ +- name: "restart timer" + systemd: + name: "{{service_name}}.timer" + state: restarted + enabled: yes + daemon_reload: yes \ No newline at end of file diff --git a/roles/systemd-timer/tasks/main.yml b/roles/systemd-timer/tasks/main.yml new file mode 100644 index 00000000..45123bdf --- /dev/null +++ b/roles/systemd-timer/tasks/main.yml @@ -0,0 +1,7 @@ +- name: create {{service_name}}.timer + template: + src: dummy.timer.j2 + dest: "/etc/systemd/system/{{service_name}}.timer" + register: dummy_timer + changed_when: dummy_timer.changed or activate_all_timers | bool + notify: restart timer \ No newline at end of file diff --git a/roles/systemd-timer/templates/dummy.timer.j2 b/roles/systemd-timer/templates/dummy.timer.j2 new file mode 100644 index 00000000..8b246dd8 --- /dev/null +++ b/roles/systemd-timer/templates/dummy.timer.j2 @@ -0,0 +1,10 @@ +[Unit] +Description=Timer to start {{service_name}}.service + +[Timer] +OnCalendar={{on_calendar}} +RandomizedDelaySec={{randomized_delay_sec}} +Persistent=false + +[Install] +WantedBy=timers.target