Replace certsync cron job with systemd timer

This commit is contained in:
Alexander Dietrich 2020-03-25 21:28:19 +01:00
parent 9497d2ca35
commit 250a0cdaac
5 changed files with 34 additions and 13 deletions

View file

@ -1,5 +1,4 @@
--- ---
certsync_dir: /etc/ssl/certsync certsync_dir: /etc/ssl/certsync
certsync_host: srv02.hamburg.freifunk.net certsync_host: srv01.hamburg.freifunk.net
certsync_key: /root/.ssh/certsync certsync_key: /root/.ssh/certsync
certsync_script: /usr/local/sbin/certsync

View file

@ -7,18 +7,24 @@
- name: template certsync script - name: template certsync script
template: template:
src: templates/certsync.j2 src: certsync
dest: "{{ certsync_script }}" dest: /usr/local/sbin/
owner: root owner: root
group: staff group: staff
mode: 0550 mode: 0550
tags: certsync tags: certsync
- name: create cronjob - name: template certsync timer
cron: template:
name: TLS Zertifikate synchronisieren src: "{{ item }}"
job: "{{ certsync_script }}" dest: /lib/systemd/system/
minute: "0" with_items:
hour: "7" - certsync.service
weekday: "1" - certsync.timer
tags: certsync
- name: enable certsync timer
systemd:
name: certsync.timer
state: started
enabled: yes
daemon_reload: yes

View file

@ -19,5 +19,5 @@ chmod 440 $CERT_DIR/*
COUNT=$(find $CERT_DIR -mtime -7 | wc -l) COUNT=$(find $CERT_DIR -mtime -7 | wc -l)
if [ $COUNT -gt 0 ]; then if [ $COUNT -gt 0 ]; then
service nginx reload > /dev/null systemctl reload nginx > /dev/null
fi fi

View file

@ -0,0 +1,6 @@
[Unit]
Description=Synchronize TLS certificates from {{ certsync_host }}
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/certsync

View file

@ -0,0 +1,10 @@
[Unit]
Description=Weekly certsync run
[Timer]
OnCalendar=Mon *-*-* 05:00
RandomizedDelaySec=60m
Persistent=true
[Install]
WantedBy=timers.target