Commit 558722b1 authored by Julian Kornberger's avatar Julian Kornberger

Migrate to systemd timers

Timers are easier to debug and give more control about the scheduling.
parent 29c56ee9
......@@ -14,5 +14,18 @@
- 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
- name: Install timer
import_role:
name: timer
vars:
timer_name: icvpn-update
timer_exec: /usr/local/bin/icvpn-update
timer_interval: 1hour
- name: Remove legacy cronjob
file:
path: /etc/cron.hourly/icvpn-update
state: absent
......@@ -24,12 +24,20 @@
name: respondd
enabled: yes
- name: Install cronjob to automatically update alfred announce
template:
src: cronjob
dest: /etc/cron.d/mesh-announce-alfred
- 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
......
# {{ ansible_managed }}
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
{% if alfred_master %}
* * * * * root sh /opt/{{ site_code }}/mesh-announce/announce.sh -i {{ alfred_mtu_interface }} -b {{ batman_interface }}
{% else %}
* * * * * root sh /opt/{{ site_code }}/mesh-announce/announce.sh -i {{ main_bridge }} -b {{ batman_interface }}
{% endif %}
......@@ -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
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
*/5 * * * * root /usr/local/bin/geojson-update
......@@ -21,4 +21,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
......@@ -30,22 +30,30 @@
- name: Install script to generate nodes zone
copy:
src: zonegen.py
dest: /usr/local/bin/zonegen.py
src: "{{ item }}"
dest: /usr/local/bin/
owner: root
group: root
mode: 0755
with_items:
- zonegen.py
- zonegen-all
- name: Install cronjob to generate nodes zone
copy:
src: cronjob
dest: /etc/cron.hourly/zonegen
owner: root
group: root
mode: 0755
- 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: /etc/cron.hourly/zonegen
service: name=zonegen.service state=started
- name: Open firewall for DNS
copy:
......
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
---
- 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: /lib/systemd/system/{{ timer_name }}.{{ item }}
with_items:
- service
- timer
register: template_result
- name: Reload systemd
command: systemctl daemon-reload
when: template_result.changed
- name: Enable and start timer
service:
name: "{{ timer_name }}.timer"
daemon_reload: yes
enabled: yes
state: started
# {{ ansible_managed }}
[Unit]
Description={{ timer_descr }}
[Service]
Type=oneshot
User={{ timer_user }}
ExecStart={{ timer_exec }}
# {{ 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment