Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to systemd timers #97

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion roles/icvpn/tasks/bird.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,20 @@
- name: Install cronjob to automatically update bgp bird configurations
template:
src: icvpn-update
dest: /etc/cron.hourly/icvpn-update
dest: /usr/local/bin/icvpn-update
mode: 0755
owner: root
group: root

- name: Install timer
import_role:
name: timer
vars:
timer_name: icvpn-update
timer_exec: /usr/local/bin/icvpn-update
timer_interval: 1hour
corny marked this conversation as resolved.
Show resolved Hide resolved

- name: Remove legacy cronjob
file:
path: /etc/cron.hourly/icvpn-update
state: absent
19 changes: 12 additions & 7 deletions roles/mesh-announce/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@
name: respondd
enabled: yes

- name: Install cronjob to automatically update alfred announce
template:
src: cronjob
dest: /etc/cron.d/mesh-announce-alfred
mode: 0644
owner: root
group: root
- name: Install timer
import_role:
name: timer
vars:
timer_name: mesh-announce
timer_exec: "/opt/{{ site_code }}/mesh-announce/announce.sh -i {{ alfred_mtu_interface if alfred_master else main_bridge }} -b {{ batman_interface }}"
timer_interval: 1min
when: mesh_announce_alfred

- name: Remove legacy cronjob
file:
path: /etc/cron.d/mesh-announce-alfred
state: absent

- name: Open firewall for respondd
template:
src: firewall.sh
Expand Down
7 changes: 0 additions & 7 deletions roles/mesh-announce/templates/cronjob

This file was deleted.

19 changes: 12 additions & 7 deletions roles/meshviewer/tasks/geojson.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
group: root
mode: 0755

- name: Install cronjob to copy valide geojson
template:
src: geojson.cronjob
dest: /etc/cron.d/geojson-update
owner: root
group: root
mode: 0644
- name: Install timer
import_role:
name: timer
vars:
timer_name: geojson-update
timer_exec: /usr/local/bin/geojson-update
timer_interval: 5min

- name: Remove legacy cronjob
file:
path: /etc/cron.d/geojson-update
state: absent
2 changes: 0 additions & 2 deletions roles/meshviewer/templates/geojson.cronjob

This file was deleted.

2 changes: 1 addition & 1 deletion roles/nsd/files/cronjob → roles/nsd/files/zonegen-all
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
--nserver dns.bremen.freifunk.net ns2.afraid.org ns2.he.net \
--file=/var/lib/nsd/0.b.a.b.b.b.f.f.2.8.7.8.6.0.a.2.ip6.arpa.zone --reverse nodes.ffhb.de. || exit

nsd-control reload > /dev/null
nsd-control reload
35 changes: 22 additions & 13 deletions roles/nsd/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,35 @@
owner: root
group: root

- name: Copy zone files
command: /usr/local/sbin/update-dns-zones.sh

- name: Install script to generate nodes zone
copy:
src: zonegen.py
dest: /usr/local/bin/zonegen.py
mode: 0755
src: "{{ item }}"
dest: /usr/local/bin/
owner: root
group: root

- name: Install cronjob to generate nodes zone
copy:
src: cronjob
dest: /etc/cron.hourly/zonegen
mode: 0755
owner: root
group: root
with_items:
- zonegen.py
- zonegen-all

- name: Install timer
import_role:
name: timer
vars:
timer_name: zonegen
timer_exec: /usr/local/bin/zonegen-all
timer_interval: 60min

- name: Remove legacy cronjob
file:
path: /etc/cron.hourly/zonegen
state: absent

- name: Initially generate nodes zone
command:
cmd: /etc/cron.hourly/zonegen
creates: /var/lib/nsd/nodes.bremen.freifunk.net.zone
service: name=zonegen.service state=started

- name: Open firewall for DNS
copy:
Expand Down
8 changes: 8 additions & 0 deletions roles/timer/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
timer_name:
timer_descr: "{{ timer_name }} Timer"
timer_exec: /bin/false
timer_user: root
timer_interval:
timer_calendar: false
timer_randomized_delay:
timer_startup_delay: 60
4 changes: 4 additions & 0 deletions roles/timer/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: reload systemd
systemd:
daemon_reload: yes
19 changes: 19 additions & 0 deletions roles/timer/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Fail when timer_name is empty
fail: msg="timer_name is empty"
when: not timer_name

- name: Upload service and timer
template:
src: "job.{{ item }}"
dest: "/etc/systemd/system/{{ timer_name }}.{{ item }}"
with_items:
- service
- timer
notify: reload systemd

- name: Enable and start timer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we always enable and start the Timer?
Maybe a deployment of generic timers would be nice - ala:
update-fastd-blacklist@.service where the variable %I could be the {{ site_code }}

service:
name: "{{ timer_name }}.timer"
enabled: yes
state: started
10 changes: 10 additions & 0 deletions roles/timer/templates/service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# {{ ansible_managed }}

[Unit]
Description={{ timer_descr }}

[Service]
Type=oneshot
User={{ timer_user }}

ExecStart={{ timer_exec }}
20 changes: 20 additions & 0 deletions roles/timer/templates/timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# {{ ansible_managed }}

[Unit]
Description={{ timer_name }} Service

[Timer]
Unit={{ timer_name }}.service
{% if timer_calendar %}
OnCalendar={{ timer_calendar }}
{% else %}
OnBootSec={{ timer_startup_delay }}
OnUnitInactiveSec={{ timer_interval }}
{% endif %}

{% if timer_randomized_delay %}
RandomizedDelaySec={{ timer_randomized_delay }}
{% endif %}

[Install]
WantedBy=basic.target