From 5f37bde7b868d67276103265fde122e871a4f1be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonah=20Br=C3=BCchert?= Date: Mon, 26 Feb 2024 23:18:38 +0100 Subject: [PATCH] ansible: Add timer for updating data and restarting motis --- ansible/hosts | 2 +- .../rsync/files/motis-update-feeds.service | 13 +++++++++ .../roles/rsync/files/motis-update-feeds.sh | 17 ++++++++++++ .../rsync/files/motis-update-feeds.timer | 13 +++++++++ ansible/roles/rsync/tasks/main.yml | 27 +++++++++++++++++++ 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 ansible/roles/rsync/files/motis-update-feeds.service create mode 100644 ansible/roles/rsync/files/motis-update-feeds.sh create mode 100644 ansible/roles/rsync/files/motis-update-feeds.timer diff --git a/ansible/hosts b/ansible/hosts index 6a31424a..0a5fed08 100644 --- a/ansible/hosts +++ b/ansible/hosts @@ -9,4 +9,4 @@ motis: ansible_host: vm-motis.spline.de transitous_nginx_site_include_extra: /etc/ssl/routing.spline.inf.fu-berlin.de/include.nginx transitous_domain: routing.spline.de - transitous_rsync_public_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIL4Pxul2Bci8Vjowx4Q75wQaAXvvWvw1HsCzxBRgi/tI jbb@hyperion" + transitous_rsync_public_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIECSh3Ot5IbFfdZYrOstBJTzSva8VUh/rz2KikvIyokn github-actions" diff --git a/ansible/roles/rsync/files/motis-update-feeds.service b/ansible/roles/rsync/files/motis-update-feeds.service new file mode 100644 index 00000000..d8721127 --- /dev/null +++ b/ansible/roles/rsync/files/motis-update-feeds.service @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2024 Jonah Brüchert +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +[Unit] +Description=Update MOTIS Feeds + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/motis-update-feeds + +[Install] +WantedBy=multi-user.target diff --git a/ansible/roles/rsync/files/motis-update-feeds.sh b/ansible/roles/rsync/files/motis-update-feeds.sh new file mode 100644 index 00000000..fcc96828 --- /dev/null +++ b/ansible/roles/rsync/files/motis-update-feeds.sh @@ -0,0 +1,17 @@ +#!/bin/bash -e +# SPDX-FileCopyrightText: 2024 Jonah Brüchert +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +echo "Copying new files…" + +# Exit if empty +if [ -z "$(ls -A /srv/rsync/transitous/)" ]; then + exit 0 +fi + +cp -r /srv/rsync/transitous/* /var/lib/motis/ +chown motis:motis -R /var/lib/motis/data/ + +echo "Restarting MOTIS…" +systemctl restart motis.service diff --git a/ansible/roles/rsync/files/motis-update-feeds.timer b/ansible/roles/rsync/files/motis-update-feeds.timer new file mode 100644 index 00000000..1247e826 --- /dev/null +++ b/ansible/roles/rsync/files/motis-update-feeds.timer @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2024 Jonah Brüchert +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +[Unit] +Description=Update MOTIS Feeds + +[Timer] +Unit=motis-update-feeds.service +OnCalendar=*-*-* 4:00:00 + +[Install] +WantedBy=timers.target diff --git a/ansible/roles/rsync/tasks/main.yml b/ansible/roles/rsync/tasks/main.yml index f2a13bc2..048054fa 100644 --- a/ansible/roles/rsync/tasks/main.yml +++ b/ansible/roles/rsync/tasks/main.yml @@ -44,4 +44,31 @@ name: rsync-ssh enabled: true masked: false + daemon_reload: true state: started + +- name: Install motis-update-feeds script + copy: + src: motis-update-feeds.sh + dest: /usr/local/bin/motis-update-feeds + mode: '0755' + +- name: Install motis-update-feeds + copy: + src: "{{ item }}" + dest: /etc/systemd/system/ + mode: '644' + with_items: + - motis-update-feeds.service + - motis-update-feeds.timer + +- name: Enable motis-update-feeds + systemd: + name: "{{ item }}" + enabled: true + masked: false + daemon_reload: true + state: started + with_items: + - motis-update-feeds.service + - motis-update-feeds.timer