diff --git a/ops/ansible/inventories/legislation.demo.openfisca.org.yml b/ops/ansible/inventories/legislation.demo.openfisca.org.yml index 3d036da2..210849a8 100644 --- a/ops/ansible/inventories/legislation.demo.openfisca.org.yml +++ b/ops/ansible/inventories/legislation.demo.openfisca.org.yml @@ -26,3 +26,5 @@ all: letsencrypt_email: contact@openfisca.org letsencrypt_environment: production + + autorestart_frequency: "*-*-* 00:10:00" diff --git a/ops/ansible/inventories/legislation.fr.openfisca.org.yml b/ops/ansible/inventories/legislation.fr.openfisca.org.yml index 02f81f64..7ae4f8ac 100644 --- a/ops/ansible/inventories/legislation.fr.openfisca.org.yml +++ b/ops/ansible/inventories/legislation.fr.openfisca.org.yml @@ -26,3 +26,5 @@ all: letsencrypt_email: contact@openfisca.org letsencrypt_environment: production + + autorestart_frequency: "*-*-* 01:10:00" diff --git a/ops/ansible/roles/legislation_explorer/defaults/main.yml b/ops/ansible/roles/legislation_explorer/defaults/main.yml index f23d5eae..ce3b4391 100644 --- a/ops/ansible/roles/legislation_explorer/defaults/main.yml +++ b/ops/ansible/roles/legislation_explorer/defaults/main.yml @@ -32,3 +32,6 @@ source_dir: legislation-explorer # relative to the home directory systemd_service_file_name: legislation-explorer.service unix_group_name: openfisca unix_user_name: legislation-explorer + +systemd_timer_file_name: "{{ systemd_service_file_name | replace('.service', '.timer') }}" +autorestart_frequency: daily diff --git a/ops/ansible/roles/legislation_explorer/tasks/main.yml b/ops/ansible/roles/legislation_explorer/tasks/main.yml index 633c1647..53f3527f 100644 --- a/ops/ansible/roles/legislation_explorer/tasks/main.yml +++ b/ops/ansible/roles/legislation_explorer/tasks/main.yml @@ -67,6 +67,11 @@ src: systemd/legislation-explorer.service.j2 dest: "/etc/systemd/system/{{ systemd_service_file_name }}" + - name: Copy the systemd timer file + ansible.builtin.template: + src: systemd/legislation-explorer.timer.j2 + dest: "/etc/systemd/system/{{ systemd_timer_file_name }}" + - name: Enable and start the systemd service ansible.builtin.systemd: daemon_reload: yes @@ -74,6 +79,13 @@ state: restarted name: "{{ systemd_service_file_name }}" + - name: Enable and start the systemd timer + ansible.builtin.systemd: + daemon_reload: yes + enabled: yes + state: started + name: "{{ systemd_timer_file_name }}" + - name: Check that Legislation Explorer is actually started ansible.builtin.uri: return_content: yes diff --git a/ops/ansible/roles/legislation_explorer/templates/systemd/legislation-explorer.timer.j2 b/ops/ansible/roles/legislation_explorer/templates/systemd/legislation-explorer.timer.j2 new file mode 100644 index 00000000..ffe93d01 --- /dev/null +++ b/ops/ansible/roles/legislation_explorer/templates/systemd/legislation-explorer.timer.j2 @@ -0,0 +1,10 @@ +[Unit] +Description=Restart OpenFisca Legislation Explorer + +[Timer] +OnCalendar={{ autorestart_frequency }} +Persistent=true +Unit={{ systemd_service_file_name }} + +[Install] +WantedBy=timers.target