f37 -> f39
[infrastructure.git] / scripts / manage-git-mirror.sh
1 #!/bin/bash
2 COMMAND=$(basename $0)
3
4 # avoid the crontab job for an hour 
5 # wait until the running instance is done and create a void stamp 
6 function stop () {
7     while true; do 
8         echo -n . 
9         ls /git-mirror/LOCK >& /dev/null || { 
10             touch /git-mirror/LOCK 
11             echo "OK, git-mirror stopped for an hour"
12             break 
13         } 
14         sleep 5
15     done
16 }
17
18 function start () {
19     if pgrep git-mirror >& /dev/null; then
20         echo "git-mirror instance is running"
21     else
22         echo "Cleaned LOCK"
23         rm /git-mirror/LOCK
24     fi
25 }
26
27 function status () {
28     pids=$(pgrep git-mirror)
29     if [ -n "$pids" ] ; then
30         echo "Active processes"
31         ps $pids
32     else
33         echo "No running instance of git-mirror"
34     fi
35     echo "Lock file status"
36     ls -l /git-mirror/LOCK
37 }
38
39 function clean () {
40     totrash=$(ls /git-mirror/*/NOTIFIED 2> /dev/null)
41     if [ -z "$totrash" ] ; then
42         echo "No NOTIFIED file found"
43     else
44         echo "Trashing the following files"
45         ls -l $totrash
46         rm -f $totrash
47         echo Done
48     fi
49 }
50
51 function main () {
52     case $1 in
53         start) start;;
54         stop) stop;;
55         status) status;;
56         clean) clean;;
57         *) echo "Usage: $COMMAND start|stop";;
58     esac
59 }
60
61 main "$@"