roles/syncrepo: Add syncrepo role
This commit is contained in:
parent
69860cdaa7
commit
58f9e031c5
6 changed files with 83 additions and 0 deletions
|
@ -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
33
roles/syncrepo/files/syncrepo
Executable 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))"
|
10
roles/syncrepo/files/syncrepo.service
Normal file
10
roles/syncrepo/files/syncrepo.service
Normal 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
|
10
roles/syncrepo/files/syncrepo.timer
Normal file
10
roles/syncrepo/files/syncrepo.timer
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Minutely repository sync
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=minutely
|
||||||
|
AccuracySec=1m
|
||||||
|
Persistent=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
4
roles/syncrepo/handlers/main.yml
Normal file
4
roles/syncrepo/handlers/main.yml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
- name: daemon reload
|
||||||
|
command: systemctl daemon-reload
|
25
roles/syncrepo/tasks/main.yml
Normal file
25
roles/syncrepo/tasks/main.yml
Normal 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
|
Loading…
Reference in a new issue