Index: trunk/ippTasks/Makefile.am
===================================================================
--- trunk/ippTasks/Makefile.am	(revision 23779)
+++ trunk/ippTasks/Makefile.am	(revision 23861)
@@ -21,4 +21,5 @@
 	replicate.pro \
 	dist.pro \
+	rcserver.pro \
 	pstamp.pro
 
Index: trunk/ippTasks/rcserver.pro
===================================================================
--- trunk/ippTasks/rcserver.pro	(revision 23861)
+++ trunk/ippTasks/rcserver.pro	(revision 23861)
@@ -0,0 +1,274 @@
+## rcserver.pro : tasks for managing the server side of the ipp data distribution system : -*- sh -*-
+
+# test for required global variables
+check.globals
+
+#$LOGSUBDIR = $LOGDIR/rcserver
+#exec mkdir -p $LOGSUBDIR
+
+### Initialise the books containing the tasks to do
+book init rcPendingFS
+book init rcPendingDS
+
+### Database lists
+$rcPendingFS_DB = 0
+$rcPendingDS_DB = 0
+
+### Check status of tasks
+macro rcserver.status
+  book listbook rcPendingFS
+  book listbook rcPendingDS
+end
+
+### Reset tasks
+macro rcserver.reset
+  book init rcPendingFS
+  book init rcPendingDS
+end
+
+### Turn tasks on
+macro rcserver.on
+  task rcserver.makefileset.load
+    active true
+  end
+  task rcserver.makefileset.run
+    active true
+  end
+  task rcserver.checkruns.load
+    active true
+  end
+  task rcserver.checkruns.run
+    active true
+  end
+end
+macro rcserver.off
+  task rcserver.makefileset.load
+    active false
+  end
+  task rcserver.makefileset.run
+    active false
+  end
+  task rcserver.checkruns.load
+    active false
+  end
+  task rcserver.checkruns.run
+    active false
+  end
+end
+
+task	       rcserver.makefileset.load
+  host         local
+
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 30
+  npending     1
+
+  stdout NULL
+  stderr $LOGDIR/rcserver.makefileset.load.log
+
+  task.exec
+    $run = disttool -pendingfileset
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      # save the DB name for the exit tasks
+      option $DB:$rcPendingFS_DB
+      $run = $run -dbname $DB:$rcPendingFS_DB
+      $rcPendingFS_DB ++
+      if ($rcPendingFS_DB >= $DB:n) set rcPendingFS_DB = 0
+    end
+    add_poll_args run
+    command $run
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout rcPendingFS -key dist_id:prod_id -uniq -setword dbname $options:0 -setword pantaskState INIT
+    if ($VERBOSE > 2)
+      book listbook rcPendingFS
+    end
+
+    # delete existing entries in the appropriate pantaskStates
+    process_cleanup rcPendingFS
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+task	       rcserver.makefileset.run
+  periods      -poll $RUNPOLL
+  periods      -exec $RUNEXEC
+  periods      -timeout 60
+
+  task.exec
+    book npages rcPendingFS -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+    
+    # look for new components to process (pantaskState == INIT)
+    book getpage rcPendingFS 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book getword rcPendingFS $pageName dist_id -var DIST_ID
+    book getword rcPendingFS $pageName target_id -var TARGET_ID
+    book getword rcPendingFS $pageName stage -var STAGE
+    book getword rcPendingFS $pageName stage_id -var STAGE_ID
+    book getword rcPendingFS $pageName dist_dir -var DIST_DIR
+#    book getword rcPendingFS $pageName clean -var CLEAN
+    book getword rcPendingFS $pageName prod_id -var PROD_ID
+    book getword rcPendingFS $pageName product_name -var PRODUCT_NAME
+    book getword rcPendingFS $pageName ds_dbhost -var DS_DBHOST
+    book getword rcPendingFS $pageName ds_dbname -var DS_DBNAME
+    book getword rcPendingFS $pageName dbname -var DBNAME
+
+#    set.host.for.camera $CAMERA $MAGIC_ID
+#    set.workdir.by.camera $CAMERA $MAGIC_ID $WORKDIR_TEMPLATE $default_host WORKDIR
+    host anyhost
+
+    sprintf logfile "%s/makefs.%s.%s.log" $DIST_DIR $DIST_ID $PROD_ID
+    stdout $logfile
+    stderr $logfile
+
+    book setword rcPendingFS $pageName pantaskState RUN
+
+    $run = dist_make_fileset.pl --dist_id $DIST_ID --target_id $TARGET_ID --stage $STAGE --stage_id $STAGE_ID --prod_id $PROD_ID --product_name $PRODUCT_NAME  --ds_dbhost $DS_DBHOST --ds_dbname $DS_DBNAME --dist_dir $DIST_DIR
+
+    add_standard_args run
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command $run
+    end
+    command $run
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit rcPendingFS $options:0 $JOB_STATUS
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword rcPendingFS $options:0 pantaskState TIMEOUT
+  end
+end
+
+
+task	       rcserver.checkruns.load
+  host         local
+
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 30
+  npending     1
+
+  active false
+
+  stdout NULL
+  stderr $LOGDIR/rcserver.checkruns.load.log
+
+  task.exec
+    $run = disttool -pendingdatastores
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      # save the DB name for the exit tasks
+      option $DB:$rcPendingDS_DB
+      $run = $run -dbname $DB:$rcPendingDS_DB
+      $rcPendingDS_DB ++
+      if ($rcPendingDS_DB >= $DB:n) set rcPendingDS_DB = 0
+    end
+    add_poll_args run
+    command $run
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout rcPendingDS -key fs_id -uniq -setword dbname $options:0 -setword pantaskState INIT
+    if ($VERBOSE > 2)
+      book listbook rcPendingDS
+    end
+
+    # delete existing entries in the appropriate pantaskStates
+    process_cleanup rcPendingDS
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+task	       rcserver.checkruns.run
+  periods      -poll $RUNPOLL
+  periods      -exec $RUNEXEC
+  periods      -timeout 60
+
+  active false
+
+  task.exec
+    book npages rcPendingDS -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+    
+    # look for new components to process (pantaskState == INIT)
+    book getpage rcPendingDS 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword rcPendingDS $pageName pantaskState RUN
+    book getword rcPendingDS $pageName dist_id -var DIST_ID
+    book getword rcPendingDS $pageName stage   -var STAGE
+    book getword rcPendingDS $pageName stage_id -var STAGE_ID
+    book getword rcPendingDS $pageName outdir -var OUTDIR
+
+    host anyhost
+
+    sprintf logfile "%s/dist.advance.%s.log" $OUTDIR $DIST_ID
+    stdout $logfile
+    stderr $logfile
+
+    $run = dist_advancerun.pl --dist_id $DIST_ID --stage $STAGE --stage_id $STAGE_ID --outdir $OUTDIR --logfile $logfile
+    add_standard_args run
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command $run
+    end
+    command $run
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit rcPendingDS $options:0 $JOB_STATUS
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword rcPendingDS $options:0 pantaskState TIMEOUT
+  end
+end
+
