The Rubis problem solverThe Rubis Server layoutThe service ports dispatcherThe Rubis spool daemon

Contents

Index

The Rubis spool daemon

To liberate the submitProblem port from the eventual finishing of the Rubis problem solver, the submitted problem files are written to the JobSpooler directory (see Figure *) which is watched for incoming jobs by the Rubis spool daemon, a bash script shown below.

#!/bin/bash
## rubisSpoolDaemon.sh 
## RB March 2008
## version 1.1
####################

# Rubis Server installation directory on Debian/Linux Ubuntu 7.10 Gutsy 
1: rootdir="/var/rubisServerData"

#  clean up when stopping the spool server
2: function cleanup {
3:     echo $(date) ' Stopping the Spool Server!' >> $rootdir/spool-log
4:     date >> $rootdir/spool-log
5:     kill "$@" $(jobs -p)
6:     exit
7: }

8: trap cleanup INT TERM 
9: trap "kill -s TERM $(jobs -p); exit" INT KILL


#  log the spool daemon starting command
11: echo $(date) ':  Rubis spool daemon started.' >> $rootdir/spool-log

#  main spooling loop
12: while true
13: do
14:       for jobFile in $rootdir/JobSpooler/*; do
15:           if [ -f $jobFile ]; then
16:              mv $jobFile $rootdir/Problems
                 ## slice the ticket out of jobFile
17: 	         ticket=${jobFile:40:16}
                 ## standard Rubis Solver
18:              python $rootdir/executeRubisSolver.py $ticket &
19:              echo $(date) ': ' $jobFile 'spooled.' >> $rootdir/spool-log
20:           fi
21:           sleep 1
22:       done
23: done

Line 1 specifies the Rubis Server installation directory. Lines 2 - 9 define a clean up function to be run when stopping the spool daemon. Upon getting the TERM signal the spool daemon will as well send a TERM signal to all its still running child processes.

The main spool loop, in Lines 12 - 23, is running for ever. For each detected entry in the JobSpooler directory (Line 14), if it is a file (Line 15) it will be first moved to the Problems directory (Line 16). Then, in Line 17, the ticket of the job is sliced out and in Line 18, the Rubis solver, with the previous ticket as argument, is started in the background. Finally, a log entry is written to the standard spool-log file.

The spool daemon is started like a SysV service on booting the server as shown in the bash script below.

#!/bin/bash
## rubis
## RB March
#############

## switching on first argument $1
1: if [ -z $1 ]; then
2: 	echo 'Usage: rubis  start | stop'
3: elif [ $1 = start ]; then
4:         pid=$(ps ax | grep rubisSpoolDaemon | grep sh)
5:         if [ -z $pid ]; then
6: 		/var/rubisServerData/rubisSpoolDaemon.sh &
7:         	pid=$(ps ax | grep rubisSpoolDaemon | grep bash)
8:         	echo "Rubis Spool Daemon started now with pid: ${pid%%\ *}"
9: 	else
10:		echo "Rubis Spool Daemon already started with pid: ${pid%%\ *}"
11: 	fi 
12: elif [ $1 = stop ]; then
13:         ## find rubisSpoolDaemon pid
14:         pidline=$(ps ax | grep rubisSpoolDaemon | grep sh)
15:         echo $pidline | { read pid rest ;\
16:                           echo  "Rubis Spool Daemon with pid = $pid";\
17:                           echo "stopping now !";\
18:                           kill $pid; \
19:                        }
20: else 
21:      echo 'Usage: rubis  start | stop'
22: fi

The Rubis spool daemon may thus be started (Lines 3 - 11) or stopped (Lines 12 - 19) with the classic command $/etc/init.d/rubis start | stop.


Raymond Bisdorff, June 2, 2008


The Rubis problem solverThe Rubis Server layoutThe service ports dispatcherThe Rubis spool daemonContentsIndex