roles/syncrepo: Add syncrepo role

This commit is contained in:
Jan Alexander Steffens (heftig) 2016-09-20 21:08:50 +02:00
parent 69860cdaa7
commit 58f9e031c5
No known key found for this signature in database
GPG key ID: A5E9288C4FA415FA
6 changed files with 83 additions and 0 deletions

View file

@ -14,3 +14,4 @@
- { role: sudo, tags: ['sudo', 'archusers'] } - { role: sudo, tags: ['sudo', 'archusers'] }
- { role: postgres, tags: ['postgres'] } - { role: postgres, tags: ['postgres'] }
- { role: quassel, quassel_domain: "quassel.archlinux.org", tags: ['quassel'] } - { role: quassel, quassel_domain: "quassel.archlinux.org", tags: ['quassel'] }
- { role: syncrepo, tags: ['syncrepo'] }

33
roles/syncrepo/files/syncrepo Executable file
View file

@ -0,0 +1,33 @@
#!/bin/bash
target="/srv/ftp"
lock='/tmp/syncrepo.lck'
source='rsync://rsync.archlinux.org/ftp_tier1'
lastupdate_url="http://rsync.archlinux.org/lastupdate"
[ ! -d "${target}" ] && mkdir -p "${target}"
exec 9>"${lock}"
flock -n 9 || exit
# if we are called without a tty (cronjob) only run when there are changes
if ! tty -s && test -f "$target/lastupdate" && diff -b <(curl -s "$lastupdate_url") "$target/lastupdate" >/dev/null; then
exit 0
fi
if stty &>/dev/null; then
VERBOSE="-h -v --progress"
else
VERBOSE="--info=name1"
fi
rsync -rtlH --safe-links --delete-after ${VERBOSE} --timeout=600 --contimeout=60 -p \
--delay-updates --no-motd \
--exclude='*.links.tar.gz*' \
--exclude='/other' \
--exclude='/sources' \
--exclude='/iso' \
${source} \
"${target}"
#echo "Last sync was $(date -d @$(cat ${target}/lastsync))"

View file

@ -0,0 +1,10 @@
[Unit]
Description=Synchronize package repository mirror
RequiresMountsFor=/srv/repo
[Service]
Type=oneshot
ExecStart=/usr/local/bin/syncrepo
Nice=19
IOSchedulingClass=best-effort
IOSchedulingPriority=7

View file

@ -0,0 +1,10 @@
[Unit]
Description=Minutely repository sync
[Timer]
OnCalendar=minutely
AccuracySec=1m
Persistent=true
[Install]
WantedBy=timers.target

View file

@ -0,0 +1,4 @@
---
- name: daemon reload
command: systemctl daemon-reload

View file

@ -0,0 +1,25 @@
---
- name: install rsync
pacman: name=rsync state=present
- name: install syncrepo script
copy: src=syncrepo dest=/usr/local/bin/syncrepo owner=root group=root mode=0755
- name: install syncrepo units
copy: src={{ item }} dest=/etc/systemd/system/{{ item }} owner=root group=root mode=0644
with_items:
- syncrepo.timer
- syncrepo.service
notify:
- daemon reload
- name: start and enable syncrepo units
service: name=syncrepo.timer enabled=yes state=started
- name: install local mirror
lineinfile:
dest: /etc/pacman.d/mirrorlist
line: 'Server = file:///srv/ftp/$repo/os/$arch'
insertbefore: BOF
create: true