jobd: Fix other check_all_projects invocations
[girocco/msimkins.git] / jobd / jobd.sh
blobdae71c9a16f6d3ccd8d09c2fee1327d6317067f3
1 #!/bin/bash
3 # jobd - Perform Girocco maintenance jobs
5 # jobd is Girocco repositories maintenance servant; it periodically
6 # checks all the repositories and updates mirrored repositories and
7 # repacks push-repositories when needed.
9 # Execute with parameter --all-once to run only once (on all projects)
10 # instead of in infinite loop. Or call with parameter --one and name
11 # of a project (not full path, without .git suffix) to run maintenance
12 # only on that particular project.
14 # Use -q as VERY FIRST parameter to enable quiet mode (use in cronjobs).
16 . @basedir@/shlib.sh
18 set -e
19 export show_progress=1
21 # Lock setup
23 if [ -e /tmp/jobd.lock ]; then
24 echo "Locked! Stale /tmp/jobd.lock?" >&2
25 exit 1
27 echo $$ >/tmp/jobd.lock
28 trap "rm /tmp/jobd.lock" SIGINT SIGTERM EXIT
31 ## Single-project routine
33 check_one_proj()
35 proj="$1"
36 if [ ! -d "$cfg_reporoot/$proj.git" ]; then
37 echo "WARNING: Skipping non-existing project $proj" >&2
38 return
40 if [ ! -e "$cfg_reporoot/$proj.git"/.nofetch ]; then
41 "$cfg_basedir"/jobd/update.sh "$proj"
43 if [ -n "$show_progress" ]; then
44 "$cfg_basedir"/jobd/gc.sh "$proj"
45 else
46 "$cfg_basedir"/jobd/gc.sh "$proj" 2>&1 | grep -v '^Pack.*created\.$'
51 ## Main loop body
53 check_all_projects()
55 start_by="$1"
56 get_repo_list | tail -n +"$start_by" | while read proj; do
57 check_one_proj "$proj"
58 done
62 ## Main program
64 if [ "$1" = "-q" ]; then
65 export show_progress=
66 shift
69 case "$1" in
70 "")
71 # Start the mirroring at a random point; if there is
72 # some problem in the update process that requires
73 # frequent restarting of jobd, this tries to give even
74 # projects late in the list a chance to get an update.
75 check_all_projects "$((RANDOM%$(get_repo_list | wc -l)))"
76 while true; do
77 check_all_projects 1
78 sleep 10
79 done;;
80 "--all-once")
81 check_all_projects 1;;
82 "--one")
83 check_one_proj "$2";;
85 echo "Usage: $0 [-q] [--all-once | --one PRJNAME]" >&2
86 exit 1;;
87 esac