Skip to content

Commit

Permalink
ansible: Add timer for updating data and restarting motis
Browse files Browse the repository at this point in the history
  • Loading branch information
jbruechert committed Feb 28, 2024
1 parent 3cdc110 commit a3609a3
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ansible/hosts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
13 changes: 13 additions & 0 deletions ansible/roles/rsync/files/motis-update-feeds.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: 2024 Jonah Brüchert <[email protected]>
#
# 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
17 changes: 17 additions & 0 deletions ansible/roles/rsync/files/motis-update-feeds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash -e
# SPDX-FileCopyrightText: 2024 Jonah Brüchert <[email protected]>
#
# 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
13 changes: 13 additions & 0 deletions ansible/roles/rsync/files/motis-update-feeds.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: 2024 Jonah Brüchert <[email protected]>
#
# 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
27 changes: 27 additions & 0 deletions ansible/roles/rsync/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a3609a3

Please sign in to comment.