cookutils rev 81

Add PID support so when running with cron we dont mess up commits
author Christophe Lincoln <pankso@slitaz.org>
date Sun May 08 01:40:02 2011 +0200 (2011-05-08)
parents 1b9322fabdf3
children 810b56de8281
files cooker
line diff
     1.1 --- a/cooker	Sun May 08 00:24:38 2011 +0200
     1.2 +++ b/cooker	Sun May 08 01:40:02 2011 +0200
     1.3 @@ -25,6 +25,9 @@
     1.4  broken="$CACHE/broken"
     1.5  cooknotes="$CACHE/cooknotes"
     1.6  
     1.7 +# PID file.
     1.8 +pidfile='/var/run/cooker.pid'
     1.9 +
    1.10  #
    1.11  # Functions
    1.12  #
    1.13 @@ -79,9 +82,10 @@
    1.14  	fi
    1.15  }
    1.16  
    1.17 -# Clean up after cook success.
    1.18 -empty_command() {
    1.19 +# Clean up before exit when check and cook commits finish.
    1.20 +clean_exit() {
    1.21  	rm -f $command && touch $command
    1.22 +	rm -f $pidfile
    1.23  }
    1.24  
    1.25  # Summary for commits.
    1.26 @@ -288,7 +292,7 @@
    1.27  	pkg|-p)
    1.28  		# Same as 'cook pkg' but with log for web interface.
    1.29  		cook $pkg || broken
    1.30 -		empty_command ;;
    1.31 +		clean_exit ;;
    1.32  	cat|-c)
    1.33  		# Cook all packages of a category.
    1.34  		cat="$2"
    1.35 @@ -355,13 +359,22 @@
    1.36  		cook_order | tee $LOGS/cookorder.log
    1.37  		cook_list ;;
    1.38  	*)
    1.39 -		# Default is to cook all commits.
    1.40 +		# Default is to cook all commits if not yet running.
    1.41  		[ "$1" ] && usage
    1.42  		cooklist=$CACHE/commits
    1.43 +		if [ -f "$pidfile" ]; then
    1.44 +			pid=$(cat /var/run/cooker.pid)
    1.45 +			gettext -e "\nStill cooking latest commits with pid:"
    1.46 +			echo -e " $pid\n" && exit 0
    1.47 +		fi
    1.48 +
    1.49 +		# Start and get a PID file.
    1.50  		rm -f $LOGS/commits.log
    1.51  		echo ""
    1.52  		echo "Checking for commits" | log_commits
    1.53  		separator | tee -a $LOGS/commits.log
    1.54 +		gettext "Starting with PID: "
    1.55 +		echo $$ | tee $pidfile
    1.56  		
    1.57  		# Get revisions.
    1.58  		cd $wok || exit 1
    1.59 @@ -381,7 +394,7 @@
    1.60  		else
    1.61  			echo "No revision changes: $cur vs $new" | log
    1.62  			separator | log_commits
    1.63 -			empty_command && echo "" && exit 0
    1.64 +			clean_exit && echo "" && exit 0
    1.65  		fi
    1.66  		
    1.67  		# Get and display modifications.
    1.68 @@ -408,7 +421,8 @@
    1.69  		echo ""
    1.70  		strip_blocked
    1.71  		cook_order | tee $LOGS/cookorder.log
    1.72 -		cook_commits && empty_command ;;
    1.73 +		cook_commits
    1.74 +		clean_exit ;;
    1.75  esac
    1.76  
    1.77  exit 0