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