Difference between revisions of "Reflector"

From ArchWiki
Jump to: navigation, search
m (country specific example)
m (Pacman hook: use redirect "pacman hook")
 
(93 intermediate revisions by 36 users not shown)
Line 1: Line 1:
 
[[Category:Package management]]
 
[[Category:Package management]]
 
[[es:Reflector]]
 
[[es:Reflector]]
 +
[[de:Reflector]]
 +
[[fr:Reflector]]
 +
[[it:Reflector]]
 +
[[ja:Reflector]]
 
[[ko:Reflector]]
 
[[ko:Reflector]]
 +
[[pl:Reflector]]
 
[[ru:Reflector]]
 
[[ru:Reflector]]
[[zh-CN:Reflector]]
+
[[zh-hans:Reflector]]
[http://xyne.archlinux.ca/projects/reflector/ Reflector] is a script which can retrieve the latest mirror list from the [https://www.archlinux.org/mirrors/status/ MirrorStatus] page, filter the most up-to-date mirrors, sort them by speed and overwrite the file {{Ic|/etc/pacman.d/mirrorlist}}.  
+
{{Related articles start}}
 +
{{Related|Mirrors}}
 +
{{Related|Pacman}}
 +
{{Related articles end}}
 +
[http://xyne.archlinux.ca/projects/reflector/ Reflector] is a script which can retrieve the latest mirror list from the [https://www.archlinux.org/mirrors/status/ MirrorStatus] page, filter the most up-to-date mirrors, sort them by speed and overwrite the file {{ic|/etc/pacman.d/mirrorlist}}.  
  
 
== Installation ==
 
== Installation ==
  
[[pacman|Install]] the {{pkg|reflector}} package which is available in the [[Official Repositories|official repositories]].
+
[[Install]] the {{Pkg|reflector}} package.
  
 
== Usage ==
 
== Usage ==
  
{{Warning|Please back up your {{ic|/etc/pacman.d/mirrorlist}} file first}}
+
{{Warning|
 +
* In the following examples, {{ic|/etc/pacman.d/mirrorlist}} will be overwritten. Make a backup before proceeding.
 +
* Make sure the resulting {{ic|/etc/pacman.d/mirrorlist}} does not contain entries that you consider untrustworthy before syncing or updating with [[Pacman]].}}
  
First back up your {{ic|/etc/pacman.d/mirrorlist}}
+
To see all of the available commands, run the following command:
  # cp -vf /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup
+
 
 +
# reflector --help
 +
 
 +
=== Examples ===
 +
 
 +
Verbosely rate and sort the five most recently synchronized mirrors by download speed, and overwrite the file {{ic|/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 {{ic|/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 {{ic|/etc/pacman.d/mirrorlist}}:
 +
 
 +
# reflector --country France --country Germany --age 12 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
 +
 
 +
== Automation ==
 +
=== Pacman hook ===
 +
 
 +
You can also create a [[pacman hook]] that will run ''reflector'' and remove the ''.pacnew'' file created every time {{Pkg|pacman-mirrorlist}} gets an upgrade.
 +
 
 +
{{hc|/etc/pacman.d/hooks/mirrorupgrade.hook|<nowiki>
 +
[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 "reflector --country 'United States' --latest 200 --age 24 --sort rate --save /etc/pacman.d/mirrorlist;  rm -f /etc/pacman.d/mirrorlist.pacnew"
 +
</nowiki>}}
 +
Make sure to substitute in your desired arguments for ''reflector''.
 +
 
 +
=== Systemd service ===
 +
This is an example of service unit that waits for the network to be up and online before running reflector:
 +
{{hc|/etc/systemd/system/reflector.service|2=
 +
[Unit]
 +
Description=Pacman mirrorlist update
 +
Wants=network-online.target
 +
After=network-online.target
 +
 
 +
[Service]
 +
Type=oneshot
 +
ExecStart=/usr/bin/reflector --protocol https --latest 30 --number 20 --sort rate --save /etc/pacman.d/mirrorlist
  
The following command will filter the first five mirrors, sort them by speed and overwrite the file {{ic|/etc/pacman.d/mirrorlist}}:
+
[Install]
# reflector --verbose -l 5 --sort rate --save /etc/pacman.d/mirrorlist
+
RequiredBy=multi-user.target
 +
}}
  
The following command will verbosely rate the 200 most recently synchronized HTTP servers, sort them by download rate, and overwrite the file {{ic|/etc/pacman.d/mirrorlist}}:
+
[[start]]ing {{ic|reflector.service}} will update the mirrorlist. To update the mirrorlist every time the computer boots, [[enable]] the service.
# reflector --verbose -l 200 -p http --sort rate --save /etc/pacman.d/mirrorlist
 
  
This command will verbosely rate the 200 most recently synchronized HTTP servers located in the US, sort them by download rate speed, and overwrite the file {{ic|/etc/pacman.d/mirrorlist}}:
+
{{Note|For more information on the implementation of the network dependency, see [[Systemd#Running services after the network is up]].}}
# reflector --verbose --country 'United States' -l 200 -p http --sort rate --save /etc/pacman.d/mirrorlist
 
  
To see all of the available commands, run the following command:
+
=== Systemd timer ===
# reflector --help
+
 
 +
If you want to run {{ic|reflector.service}} on a weekly basis, create an associated ''.timer'':
 +
 
 +
{{hc|/etc/systemd/system/reflector.timer|2=
 +
[Unit]
 +
Description=Run reflector weekly
 +
 
 +
[Timer]
 +
OnCalendar=Mon *-*-* 7:00:00
 +
RandomizedDelaySec=15h
 +
Persistent=true
 +
 
 +
[Install]
 +
WantedBy=timers.target
 +
}}
 +
 
 +
And then just [[start]] the {{ic|reflector.timer}}.
 +
 
 +
=== Reflector-timer package ===
 +
 
 +
[[Install]] {{AUR|reflector-timer}} to run ''reflector'' weekly.
 +
 
 +
The default configuration, which can be edited to fit one's needs, is:
 +
{{hc|/usr/share/reflector-timer/reflector.conf|2=
 +
AGE=6
 +
COUNTRY=Germany
 +
LATEST=30
 +
NUMBER=20
 +
SORT=rate
 +
### remove an entry if you don't want it as available protocol
 +
PROTOCOL1='-p http'
 +
PROTOCOL2='-p https'
 +
PROTOCOL3='-p ftp'
 +
PROTOCOL4='-p rsync'
 +
}}
  
{{Warning|Make sure the mirror list does not contain strange entries before syncing or updating with pacman.}}
+
Be sure to [[enable]] {{ic|reflector.timer}}.

Latest revision as of 13:33, 23 April 2018

Reflector is a script which can retrieve the latest mirror list from the MirrorStatus 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

Pacman hook

You can also create a pacman hook that will run reflector 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 "reflector --country 'United States' --latest 200 --age 24 --sort rate --save /etc/pacman.d/mirrorlist;  rm -f /etc/pacman.d/mirrorlist.pacnew"

Make sure to substitute in your desired arguments for reflector.

Systemd service

This is an example of service unit that waits for the network to be up and online before running reflector:

/etc/systemd/system/reflector.service
[Unit]
Description=Pacman mirrorlist update
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/reflector --protocol https --latest 30 --number 20 --sort rate --save /etc/pacman.d/mirrorlist

[Install]
RequiredBy=multi-user.target

starting reflector.service will update the mirrorlist. To update the mirrorlist every time the computer boots, enable the service.

Note: For more information on the implementation of the network dependency, see Systemd#Running services after the network is up.

Systemd timer

If you want to run reflector.service on a weekly basis, create an associated .timer:

/etc/systemd/system/reflector.timer
[Unit]
Description=Run reflector weekly

[Timer]
OnCalendar=Mon *-*-* 7:00:00
RandomizedDelaySec=15h
Persistent=true

[Install]
WantedBy=timers.target

And then just start the reflector.timer.

Reflector-timer package

Install reflector-timerAUR to run reflector weekly.

The default configuration, which can be edited to fit one's needs, is:

/usr/share/reflector-timer/reflector.conf
AGE=6
COUNTRY=Germany
LATEST=30
NUMBER=20
SORT=rate
### remove an entry if you don't want it as available protocol
PROTOCOL1='-p http'
PROTOCOL2='-p https'
PROTOCOL3='-p ftp'
PROTOCOL4='-p rsync'

Be sure to enable reflector.timer.