From 41d69eb95f49cdee72b4b08b3613849aa0ecfbfd Mon Sep 17 00:00:00 2001 From: Sven Feyerabend Date: Wed, 22 May 2024 18:10:04 +0200 Subject: [PATCH] feat(systemd): nightly reboot --- handlers/main.yml | 4 ++++ tasks/main.yml | 21 +++++++++++++++++++++ templates/reboot.service.j2 | 7 +++++++ templates/reboot.timer.j2 | 11 +++++++++++ 4 files changed, 43 insertions(+) create mode 100644 handlers/main.yml create mode 100644 templates/reboot.service.j2 create mode 100644 templates/reboot.timer.j2 diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..8980dd4 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,4 @@ +--- +- name: Reload systemd configuration + service: + daemon_reload: True diff --git a/tasks/main.yml b/tasks/main.yml index 9de76ef..3a382b2 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -51,3 +51,24 @@ template: src: start-waydroid.sh.j2 dest: /usr/local/bin/start-waydroid.sh + +- name: Create reboot service + template: + src: reboot.service.j2 + dest: /etc/systemd/system/reboot.service + notify: + - Reload systemd configuration + +- name: Create reboot timer + template: + src: reboot.timer.j2 + dest: /etc/systemd/system/reboot.timer + notify: + - Reload systemd configuration + + +- name: Enable reboot timer + systemd: + name: reboot.timer + enabled: True + state: started diff --git a/templates/reboot.service.j2 b/templates/reboot.service.j2 new file mode 100644 index 0000000..af5eb89 --- /dev/null +++ b/templates/reboot.service.j2 @@ -0,0 +1,7 @@ +# {{ansible_managed}} +[Unit] +Description=Reboot the system + +[Service] +Type=oneshot +ExecStart=/usr/bin/systemctl reboot diff --git a/templates/reboot.timer.j2 b/templates/reboot.timer.j2 new file mode 100644 index 0000000..6a3bab1 --- /dev/null +++ b/templates/reboot.timer.j2 @@ -0,0 +1,11 @@ +# {{ansible_managed}} +[Unit] +Description=Schedule nightly reboot for the system +Requisite=reboot.service + +[Timer] +OnCalendar=*-*-* 03:00:00 +Persistent=true + +[Install] +WantedBy=timers.target