Difference between revisions of "How to setup a Alpine Linux mirror"

From Alpine Linux
Jump to: navigation, search
(Created page with 'File:sync.sh')
 
(initial howto configure rsync and lighttpd for a mirror)
Line 1: Line 1:
 +
This document describes how to set up an Alpine Linux mirror and make it available via http and rsync.
 +
 +
We will:
 +
* create the dir where we have the mirror
 +
* set up a cron job to sync with master mirror every hour
 +
* set up lighttpd for http access
 +
* set up rsync so other mirrors can rsync from you
 +
 +
== Setting up the cron job ==
 +
Install rsync which will be used to sync from the master mirror.
 +
{{Cmd|apk add rsync}}
 +
 +
Save the following file as ''/etc/periodic/hourly/alpine-mirror''
 +
<pre>
 +
#!/bin/sh
 +
 +
# make sure we never run 2 rsync at the same time
 +
lockfile="/tmp/alpine-mirror.lock"
 +
if [ -z "$flock" ] ; then
 +
  exec env flock=1 flock -n $lockfile $0 "$@"
 +
fi
 +
 +
src=rsync://rsync.alpinelinux.org/alpine/
 +
dest=/var/www/localhost/htdocs/alpine/
 +
 +
# uncomment this to only include v1.8 or newer
 +
#exclude="--exclude v1.[1-7]"
 +
 +
mkdir -p "$dest"
 +
/usr/bin/rsync -prua \
 +
        $exclude \
 +
        --delete \
 +
        --timeout=600 \
 +
        --delay-updates \
 +
        --delete-after \
 +
        "$src" "$dest"
 +
 +
</pre>
 +
 +
Make it executable:
 +
{{Cmd|<nowiki>chmod +x /etc/periodic/hourly/alpine-mirror</nowiki>}}
 +
 +
Now it will sync every hour. (given cron runs)
 +
 +
== Setting up HTTP access via lighttpd ==
 +
Install the lighttpd server
 +
{{Cmd|apk add lighttpd}}
 +
 +
Enable dir listings by uncommenting the following line in ''/etc/lighttpd/lighttpd.conf'':
 +
dir-listing.activate      = "enable"
 +
 +
Start lighttpd and make it start at boot:
 +
{{Cmd|rc-service lighttpd start
 +
rc-update add lighttpd}}
 +
 +
== Setting up rsyncd ==
 +
Add the following lines to ''/etc/rsyncd.conf'':
 +
<pre>
 +
[alpine]
 +
        path = /var/www/localhost/htdocs/alpine
 +
        comment = My Alpine Linux Mirror
 +
</pre>
 +
 +
Optionally set a bandwidth limit in ''/etc/conf.d/rsyncd''. In this example we limit to 500Kbytes/s (approx 5Mbit/s)
 +
<pre>
 +
RSYNC_OPTS="--bwlimit=500"
 +
</pre>
 +
 +
 +
 +
Reference:
 
[[File:sync.sh]]
 
[[File:sync.sh]]

Revision as of 02:38, 18 June 2010

This document describes how to set up an Alpine Linux mirror and make it available via http and rsync.

We will:

  • create the dir where we have the mirror
  • set up a cron job to sync with master mirror every hour
  • set up lighttpd for http access
  • set up rsync so other mirrors can rsync from you

Setting up the cron job

Install rsync which will be used to sync from the master mirror.

apk add rsync

Save the following file as /etc/periodic/hourly/alpine-mirror

#!/bin/sh

# make sure we never run 2 rsync at the same time
lockfile="/tmp/alpine-mirror.lock"
if [ -z "$flock" ] ; then
  exec env flock=1 flock -n $lockfile $0 "$@"
fi

src=rsync://rsync.alpinelinux.org/alpine/ 
dest=/var/www/localhost/htdocs/alpine/

# uncomment this to only include v1.8 or newer
#exclude="--exclude v1.[1-7]"

mkdir -p "$dest"
/usr/bin/rsync -prua \
        $exclude \
        --delete \
        --timeout=600 \
        --delay-updates \
        --delete-after \
        "$src" "$dest"

Make it executable:

chmod +x /etc/periodic/hourly/alpine-mirror

Now it will sync every hour. (given cron runs)

Setting up HTTP access via lighttpd

Install the lighttpd server

apk add lighttpd

Enable dir listings by uncommenting the following line in /etc/lighttpd/lighttpd.conf:

dir-listing.activate      = "enable"

Start lighttpd and make it start at boot:

rc-service lighttpd start rc-update add lighttpd

Setting up rsyncd

Add the following lines to /etc/rsyncd.conf:

[alpine]
        path = /var/www/localhost/htdocs/alpine
        comment = My Alpine Linux Mirror

Optionally set a bandwidth limit in /etc/conf.d/rsyncd. In this example we limit to 500Kbytes/s (approx 5Mbit/s)

RSYNC_OPTS="--bwlimit=500"


Reference: File:Sync.sh