add systemd timer to update pacman mirrors daily

This increases the likelihood of speedy and up-to-date mirrors,
particularly during travel.
This commit is contained in:
Pig Monkey 2018-11-17 21:38:45 -08:00
parent ceb1526498
commit c4be5e5e7b
10 changed files with 88 additions and 14 deletions

View file

@ -71,7 +71,6 @@ base_packages:
- coreutils - coreutils
- moreutils - moreutils
- dateutils - dateutils
- reflector
- bc - bc
- ranger - ranger
- strace - strace
@ -283,4 +282,7 @@ aur_fonts:
syncthing: syncthing:
run_on: trusted run_on: trusted
mirrorlist:
run_on: trusted
kernel_parameters: "quiet consoleblank=60 i915.enable_psr=2" kernel_parameters: "quiet consoleblank=60 i915.enable_psr=2"

View file

@ -74,6 +74,7 @@
- { role: himawaripy, tags: ['himawaripy'], when: "himawaripy is defined" } - { role: himawaripy, tags: ['himawaripy'], when: "himawaripy is defined" }
- { role: kiwix, tags: ['kiwix'] } - { role: kiwix, tags: ['kiwix'] }
- { role: syncthing, tags: ['syncthing'], when: "syncthing is defined" } - { role: syncthing, tags: ['syncthing'], when: "syncthing is defined" }
- { role: mirrorlist, tags: ['mirrorlist'], when: "mirrorlist is defined" }
vars_prompt: vars_prompt:
- name: user_password - name: user_password
prompt: "Enter desired user password" prompt: "Enter desired user password"

View file

@ -6,25 +6,12 @@
tags: tags:
- packages - packages
- name: Push reflector update script
copy:
src: reflector-update.sh
dest: /usr/local/bin/reflector-update
mode: 0755
tags:
- packages
- name: Create pacman hook directory - name: Create pacman hook directory
file: path=/etc/pacman.d/hooks file: path=/etc/pacman.d/hooks
state=directory state=directory
tags: tags:
- packages - packages
- name: Push pacman mirror list update hook
copy: src=mirrorlist.hook dest=/etc/pacman.d/hooks/mirrorlist.hook
tags:
- packages
- name: Use all cores when compressing packages - name: Use all cores when compressing packages
lineinfile: lineinfile:
dest: /etc/makepkg.conf dest: /etc/makepkg.conf

View file

@ -0,0 +1,7 @@
[Unit]
Description=Reflector Update Service
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/reflector-update

View file

@ -0,0 +1,11 @@
[Unit]
Description=Reflector Update Timer
[Timer]
Unit=reflector-update.service
OnCalendar=daily
Persistent=True
RandomizedDelaySec=1h
[Install]
WantedBy=timers.target

View file

@ -0,0 +1,4 @@
---
- name: restart reflector update
service: name=mirrorlist.timer state=restarted
when: mirrorlist.run_on == "all"

View file

@ -0,0 +1,4 @@
---
dependencies:
- { role: networkmanager }
- { role: systemd }

View file

@ -0,0 +1,58 @@
---
- name: Install reflector
pacman:
name: reflector
state: present
- name: Push reflector update script
copy:
src: reflector-update.sh
dest: /usr/local/bin/reflector-update
mode: 0755
- name: Push pacman mirror list update hook
copy:
src: mirrorlist.hook
dest: /etc/pacman.d/hooks/mirrorlist.hook
- name: Push reflector update service file
copy:
src: reflector-update.service
dest: /etc/systemd/system/
notify:
- reload systemd config
- name: Push reflector update timer file
copy:
src: reflector-update.timer
dest: /etc/systemd/system/
notify:
- reload systemd config
- restart reflector update
- name: Enable and start reflector timer
service:
name: reflector-update.timer
enabled: yes
state: started
when: mirrorlist.run_on == "all"
- name: Remove reflector from trusted unit list
lineinfile:
dest: /usr/local/etc/trusted_units
state: absent
line: reflector-update.timer
when: mirrorlist.run_on == "all"
- name: Disable reflector timer
service:
name: reflector-update.timer
enabled: no
when: mirrorlist.run_on == "trusted"
- name: Add reflector to trusted unit list
lineinfile:
dest: /usr/local/etc/trusted_units
state: present
line: reflector-update.timer
when: mirrorlist.run_on == "trusted"