From c4be5e5e7b3d5a8ae99083fc5bccf1e4d1d56b94 Mon Sep 17 00:00:00 2001 From: Pig Monkey Date: Sat, 17 Nov 2018 21:38:45 -0800 Subject: [PATCH] add systemd timer to update pacman mirrors daily This increases the likelihood of speedy and up-to-date mirrors, particularly during travel. --- group_vars/all | 4 +- playbook.yml | 1 + roles/base/tasks/packages.yml | 13 ----- .../files/mirrorlist.hook | 0 .../mirrorlist/files/reflector-update.service | 7 +++ .../files/reflector-update.sh | 0 roles/mirrorlist/files/reflector-update.timer | 11 ++++ roles/mirrorlist/handlers/main.yml | 4 ++ roles/mirrorlist/meta/main.yml | 4 ++ roles/mirrorlist/tasks/main.yml | 58 +++++++++++++++++++ 10 files changed, 88 insertions(+), 14 deletions(-) rename roles/{base => mirrorlist}/files/mirrorlist.hook (100%) create mode 100644 roles/mirrorlist/files/reflector-update.service rename roles/{base => mirrorlist}/files/reflector-update.sh (100%) create mode 100644 roles/mirrorlist/files/reflector-update.timer create mode 100644 roles/mirrorlist/handlers/main.yml create mode 100644 roles/mirrorlist/meta/main.yml create mode 100644 roles/mirrorlist/tasks/main.yml diff --git a/group_vars/all b/group_vars/all index 13bd82e..6e1de7f 100644 --- a/group_vars/all +++ b/group_vars/all @@ -71,7 +71,6 @@ base_packages: - coreutils - moreutils - dateutils - - reflector - bc - ranger - strace @@ -283,4 +282,7 @@ aur_fonts: syncthing: run_on: trusted +mirrorlist: + run_on: trusted + kernel_parameters: "quiet consoleblank=60 i915.enable_psr=2" diff --git a/playbook.yml b/playbook.yml index d2731c6..c59d750 100644 --- a/playbook.yml +++ b/playbook.yml @@ -74,6 +74,7 @@ - { role: himawaripy, tags: ['himawaripy'], when: "himawaripy is defined" } - { role: kiwix, tags: ['kiwix'] } - { role: syncthing, tags: ['syncthing'], when: "syncthing is defined" } + - { role: mirrorlist, tags: ['mirrorlist'], when: "mirrorlist is defined" } vars_prompt: - name: user_password prompt: "Enter desired user password" diff --git a/roles/base/tasks/packages.yml b/roles/base/tasks/packages.yml index da3b293..e40d02c 100644 --- a/roles/base/tasks/packages.yml +++ b/roles/base/tasks/packages.yml @@ -6,25 +6,12 @@ tags: - 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 file: path=/etc/pacman.d/hooks state=directory tags: - 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 lineinfile: dest: /etc/makepkg.conf diff --git a/roles/base/files/mirrorlist.hook b/roles/mirrorlist/files/mirrorlist.hook similarity index 100% rename from roles/base/files/mirrorlist.hook rename to roles/mirrorlist/files/mirrorlist.hook diff --git a/roles/mirrorlist/files/reflector-update.service b/roles/mirrorlist/files/reflector-update.service new file mode 100644 index 0000000..2848d0a --- /dev/null +++ b/roles/mirrorlist/files/reflector-update.service @@ -0,0 +1,7 @@ +[Unit] +Description=Reflector Update Service +After=network.target + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/reflector-update diff --git a/roles/base/files/reflector-update.sh b/roles/mirrorlist/files/reflector-update.sh similarity index 100% rename from roles/base/files/reflector-update.sh rename to roles/mirrorlist/files/reflector-update.sh diff --git a/roles/mirrorlist/files/reflector-update.timer b/roles/mirrorlist/files/reflector-update.timer new file mode 100644 index 0000000..dd4be32 --- /dev/null +++ b/roles/mirrorlist/files/reflector-update.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Reflector Update Timer + +[Timer] +Unit=reflector-update.service +OnCalendar=daily +Persistent=True +RandomizedDelaySec=1h + +[Install] +WantedBy=timers.target diff --git a/roles/mirrorlist/handlers/main.yml b/roles/mirrorlist/handlers/main.yml new file mode 100644 index 0000000..8436a6c --- /dev/null +++ b/roles/mirrorlist/handlers/main.yml @@ -0,0 +1,4 @@ +--- +- name: restart reflector update + service: name=mirrorlist.timer state=restarted + when: mirrorlist.run_on == "all" diff --git a/roles/mirrorlist/meta/main.yml b/roles/mirrorlist/meta/main.yml new file mode 100644 index 0000000..54f727d --- /dev/null +++ b/roles/mirrorlist/meta/main.yml @@ -0,0 +1,4 @@ +--- +dependencies: + - { role: networkmanager } + - { role: systemd } diff --git a/roles/mirrorlist/tasks/main.yml b/roles/mirrorlist/tasks/main.yml new file mode 100644 index 0000000..68c62d8 --- /dev/null +++ b/roles/mirrorlist/tasks/main.yml @@ -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"