9c24c7d38020005761815a106184318e93258aaa
[mirror-admin] / bin / run-mirrors
1 #! /bin/sh
2
3 set -e
4
5 ## Make sure we're running as the right user.
6 case $(id -un) in
7 mirror) ;;
8 *) exec userv -fstdin=/dev/null mirror run ;;
9 esac
10
11 ## Set up a plausible environment.
12 HOME=/var/lib/mirror-admin; export HOME; cd
13 MIRRORS=/mnt/mirrors; export MIRRORS
14 PATH=$HOME/bin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin:/usr/local/sbin
15 export PATH
16 umask 002
17
18 ## Make sure we're running with a lock file.
19 case "${MIRROR_LOCKED-nil}" in
20 nil) exec env MIRROR_LOCKED=t locking -f var/mirror.lock "$0" "$@" ;;
21 esac
22
23 ## Hack for mad Kerberized NFS.
24 if [ -r etc/krb5.keytab ]; then
25 kinit -k -t etc/krb5.keytab mirror
26 fi
27
28 ## Before we start, rotate the logs. (Doing things this way means that we
29 ## can be sure we don't lose new logs, even if the log rotation goes
30 ## completely mental.
31 logrotate -s var/logrotate.state etc/logrotate.conf
32
33 ## Let SIGINT take out the children only.
34 trap "" INT
35
36 ## Now do the various mirroring things.
37 for file in $(run-parts --list etc/mirrors.d); do
38 [ -x "$file" ] || continue
39 base=${file##*/}; base=${base#[0-9]*-}
40 (
41 echo
42 echo "***--------------------------------------------------"
43 echo "*** Running $base at $(date +%Y-%m-%dT%H:%M:%S)"
44 echo
45 set +e; (trap - INT; exec "$file"); rc=$?; set -e
46 echo
47 echo "*** Finished $(date +%Y-%m-%dT%H:%M:%S); rc = $rc"
48 ) >>log/$base.log 2>&1
49 done