Reflector

From ArchWiki
Jump to navigation Jump to search

Reflector is a Python script which can retrieve the latest mirror list from the Arch Linux Mirror Status page, filter the most up-to-date mirrors, sort them by speed and overwrite the file /etc/pacman.d/mirrorlist.

Installation

Install the reflector package.

Usage

Warning:
  • In the following examples, /etc/pacman.d/mirrorlist will be overwritten. Make a backup before proceeding.
  • Make sure the resulting /etc/pacman.d/mirrorlist does not contain entries that you consider untrustworthy before syncing or updating with pacman.

To see all of the available commands, run the following command:

$ reflector --help

Examples

Verbosely rate and sort the five most recently synchronized mirrors by download speed, and overwrite the file /etc/pacman.d/mirrorlist:

# reflector --verbose --latest 5 --sort rate --save /etc/pacman.d/mirrorlist

Select the 200 most recently synchronized HTTP or HTTPS mirrors, sort them by download speed, and overwrite the file /etc/pacman.d/mirrorlist:

# reflector --latest 200 --protocol http --protocol https --sort rate --save /etc/pacman.d/mirrorlist

Select the HTTPS mirrors synchronized within the last 12 hours and located in either France or Germany, sort them by download speed, and overwrite the file /etc/pacman.d/mirrorlist:

# reflector --country France --country Germany --age 12 --protocol https --sort rate --save /etc/pacman.d/mirrorlist

Automation

systemd service

Since version 2020.8, Reflector ships with an enableable reflector.service.

The service will run reflector with the parameters specified in /etc/xdg/reflector/reflector.conf. This file accepts all of the reflector command-line arguments. Arguments may be grouped together on a single line or split across many lines, with optional blank lines and comment lines beginning with #. The default configuration file should serve as a good starting point and example.

For example, to select the 5 most up-to-date mirrors from France and Germany that support HTTPS and override /etc/pacman.d/mirrorlist, use

/etc/xdg/reflector/reflector.conf
--save /etc/pacman.d/mirrorlist
--country France,Germany
--protocol https
--latest 5

Enable reflector.service to run Reflector on boot. To run it immediately, start the service.

systemd timer

Since version 2020.8, Reflector provides a systemd timer (reflector.timer) that starts the #systemd service reflector.service weekly. The schedule can be changed by editing reflector.timer.

First edit the configuration file as described in #systemd service. After you have updated the configuration file, start and enable reflector.timer.

To refresh the mirrorlist ahead of schedule, start reflector.service.

pacman hook

Tango-edit-cut.pngThis section is being considered for removal.Tango-edit-cut.png

Reason: pacman-mirrorlist is not updated regularly, invoking reflector only because some mirror on the other side of the globe was added or removed does not make sense. It also does not make sense to provide a hook just because it is possible, since the package provides a timer-based automation. Automating the removal of mirrorlist.pacnew does not make sense; if you do not want the file at all, use NoExtract in pacman.conf. (Discuss in Talk:Reflector#Pacman hook)

You can create a pacman hook that will start reflector.service and remove the .pacnew file created every time pacman-mirrorlist gets an upgrade.

/etc/pacman.d/hooks/mirrorupgrade.hook
[Trigger]
Operation = Upgrade
Type = Package
Target = pacman-mirrorlist

[Action]
Description = Updating pacman-mirrorlist with reflector and removing pacnew...
When = PostTransaction
Depends = reflector
Exec = /bin/sh -c 'systemctl start reflector.service; if [ -f /etc/pacman.d/mirrorlist.pacnew ]; then rm /etc/pacman.d/mirrorlist.pacnew; fi'

Set desired mirror options in /etc/xdg/reflector/reflector.conf as described in #systemd service.

This is also provided by reflector-mirrorlist-updateAUR.

Cron task

Tango-edit-cut.pngThis section is being considered for removal.Tango-edit-cut.png

Reason: No reason to provide an alternative for #systemd timer which is included in the package. (Discuss in Talk:Reflector#)

To update the mirrorlist daily, consider the following:

/etc/cron.daily/mirrorlist
#!/bin/bash

# Get the country thing
/usr/bin/reflector -c "India" -p http --sort rate > /etc/pacman.d/mirrorlist

# Work through the alternatives
/usr/bin/reflector -p http  --latest 20 -p https -p ftp --sort rate >> /etc/pacman.d/mirrorlist

See also