From d00a59aceb7b1f10b852bd7ce253f1df57fb27fd Mon Sep 17 00:00:00 2001 From: Morten Linderud <morten@linderud.pw> Date: Sun, 17 Jan 2021 19:01:09 +0100 Subject: [PATCH] Added syncdebug role Signed-off-by: Morten Linderud <morten@linderud.pw> --- .../dbscripts/templates/rsyncd.conf.proto.j2 | 9 +++++ roles/syncdebug/files/syncdebug | 34 +++++++++++++++++++ roles/syncdebug/files/syncdebug.service | 12 +++++++ roles/syncdebug/files/syncdebug.timer | 10 ++++++ roles/syncdebug/tasks/main.yml | 21 ++++++++++++ 5 files changed, 86 insertions(+) create mode 100755 roles/syncdebug/files/syncdebug create mode 100644 roles/syncdebug/files/syncdebug.service create mode 100644 roles/syncdebug/files/syncdebug.timer create mode 100644 roles/syncdebug/tasks/main.yml diff --git a/roles/dbscripts/templates/rsyncd.conf.proto.j2 b/roles/dbscripts/templates/rsyncd.conf.proto.j2 index 715cb5591..81c2c1087 100644 --- a/roles/dbscripts/templates/rsyncd.conf.proto.j2 +++ b/roles/dbscripts/templates/rsyncd.conf.proto.j2 @@ -91,6 +91,15 @@ hosts deny = * secrets file = /etc/rsyncd.secrets max connections = 0 +# Debug repositories +[debug_packages] + path = /srv/ftp + comment = debug packages + exclude = * + include = /pool /pool/*-debug/*** + hosts allow = {{ hostvars['debuginfod.archlinux.org']['ipv4_address'] }} {{ hostvars['debuginfod.archlinux.org']['ipv6_address'] }} + max connections = 0 + # Individual repositories [core] path = /srv/ftp/core diff --git a/roles/syncdebug/files/syncdebug b/roles/syncdebug/files/syncdebug new file mode 100755 index 000000000..a1d41bd3e --- /dev/null +++ b/roles/syncdebug/files/syncdebug @@ -0,0 +1,34 @@ +#!/bin/bash + +target="/srv/ftp" +lock="/var/lock/syncdebug.lck" +source_url='rsync://rsync.archlinux.org/debug_packages' +lastupdate_url='https://rsync.archlinux.org/lastupdate' + +[ ! -d "${target}" ] && mkdir -p "${target}" + +exec 9>"${lock}" +flock -n 9 || exit + +rsync_cmd() { + local -a cmd=(rsync -rlptH --safe-links --delete-delay --delay-updates + "--timeout=600" "--contimeout=60" --no-motd) + + if stty &>/dev/null; then + cmd+=(-h -v --progress) + else + cmd+=("--info=name1") + fi + + "${cmd[@]}" "$@" +} + +# if we are called without a tty (cronjob) only run when there are changes +if ! tty -s && [[ -f "$target/lastupdate" ]] && diff -b <(curl -Ls "$lastupdate_url") "$target/lastupdate" >/dev/null; then + exit 0 +fi + +rsync_cmd \ + --exclude=".well-known" \ + "${source_url}" \ + "${target}" diff --git a/roles/syncdebug/files/syncdebug.service b/roles/syncdebug/files/syncdebug.service new file mode 100644 index 000000000..48d1c40fc --- /dev/null +++ b/roles/syncdebug/files/syncdebug.service @@ -0,0 +1,12 @@ +[Unit] +Description=Synchronize debug packages +RequiresMountsFor=/srv/ftp +Wants=network-online.target +After=network-online.target + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/syncdebug +Nice=19 +IOSchedulingClass=best-effort +IOSchedulingPriority=7 diff --git a/roles/syncdebug/files/syncdebug.timer b/roles/syncdebug/files/syncdebug.timer new file mode 100644 index 000000000..c4288b8a7 --- /dev/null +++ b/roles/syncdebug/files/syncdebug.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Sync debug packages every 4 hours + +[Timer] +OnCalendar=00/4:00 +AccuracySec=1m +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/roles/syncdebug/tasks/main.yml b/roles/syncdebug/tasks/main.yml new file mode 100644 index 000000000..0220b0699 --- /dev/null +++ b/roles/syncdebug/tasks/main.yml @@ -0,0 +1,21 @@ +--- +- name: install rsync + pacman: name=rsync state=present + +- name: install syncdebug script + copy: src=syncdebug dest=/usr/local/bin/syncdebug owner=root group=root mode=0755 + +- name: install syncdebug units + copy: src={{ item }} dest=/etc/systemd/system/{{ item }} owner=root group=root mode=0644 + with_items: + - syncdebug.timer + - syncdebug.service + +- name: start and enable syncdebug units + systemd: + name: "{{ item }}" + enabled: true + state: started + daemon_reload: true + with_items: + - syncdebug.timer -- GitLab