2 #------------------------------------------------------------------
4 # Purpose: A batch worker script for stoping a sam project.
5 # This script should run after all workers finish.
9 # condor_stop_project.sh [options]
11 # --sam_station <arg> - Specify sam station (required).
12 # --sam_project <arg> - Sam project name (required).
13 # --logdir <arg> - Specify log directory (optional).
14 # -g, --grid - Be grid-friendly.
15 # --init <path> - Absolute path of environment initialization script (optional).
19 # Created: H. Greenlee, 29-Aug-2012
21 #------------------------------------------------------------------
32 while [ $# -gt 0 ]; do
37 awk '/^# Usage:/,/^# End options/{print $0}' $0 | cut -c3- | head -n -2
70 # Specify environment initialization script path.
80 echo "Unknown option $1"
86 # Done with arguments.
88 echo "Nodename: `hostname`"
90 # Check and print configuraiton options.
92 echo "Sam station: $SAM_STATION"
93 echo "Sam project name: $SAM_PROJECT"
95 # Complain if SAM_STATION is not defined.
97 if [ x$SAM_STATION = x ]; then
98 echo "Sam station was not specified (use option --sam_station)."
102 # Complain if SAM_PROJECT is not defined.
104 if [ x$SAM_PROJECT = x ]; then
105 echo "Sam project name was not specified (use option --sam_project)."
109 # Initialize ups products and mrb.
111 echo "Initializing ups and mrb."
113 if [ x$INIT != x ]; then
114 if [ ! -f $INIT ]; then
115 echo "Environment initialization script $INIT not found."
118 echo "Sourcing $INIT"
121 echo "Sourcing setup_experiment.sh"
122 source ${CONDOR_DIR_INPUT}/setup_experiment.sh
125 echo PRODUCTS=$PRODUCTS
127 # Ifdh may already be setup by jobsub wrapper.
128 # If not, set it up here.
130 echo "IFDHC_DIR=$IFDHC_DIR"
131 if [ x$IFDHC_DIR = x ]; then
132 echo "Setting up ifdhc, because jobsub did not set it up."
135 echo "IFDHC_DIR=$IFDHC_DIR"
137 # Set options for ifdh.
139 #if [ $GRID -ne 0 ]; then
140 # echo "X509_USER_PROXY = $X509_USER_PROXY"
141 # if ! echo $X509_USER_PROXY | grep -q Production; then
142 # IFDH_OPT="--force=expgridftp"
145 echo "IFDH_OPT=$IFDH_OPT"
147 # Create the scratch directory in the condor scratch diretory.
148 # Copied from condor_lBdetMC.sh.
149 # Scratch directory path is stored in $TMP.
150 # Scratch directory is automatically deleted when shell exits.
152 # Do not change this section.
153 # It creates a temporary working directory that automatically cleans up all
154 # leftover files at the end.
155 TMP=`mktemp -d ${_CONDOR_SCRATCH_DIR}/working_dir.XXXXXXXXXX`
156 TMP=${TMP:-${_CONDOR_SCRATCH_DIR}/working_dir.$$}
158 { [[ -n "$TMP" ]] && mkdir -p "$TMP"; } || \
159 { echo "ERROR: unable to create temporary directory!" 1>&2; exit 1; }
160 trap "[[ -n \"$TMP\" ]] && { rm -rf \"$TMP\"; }" 0
162 # End of the section you should not change.
164 echo "Scratch directory: $TMP"
166 # See if we need to set umask for group write.
168 LOGDIR=`echo $LOGDIR | sed 's/@s/sam/'`
169 if [ $GRID -eq 0 -a x$LOGDIR != x ]; then
170 LOGUSER=`stat -c %U $LOGDIR`
172 if [ $LOGUSER != $CURUSER ]; then
173 echo "Setting umask for group write."
178 # Save the project name in a file.
180 echo $SAM_PROJECT > sam_project.txt
184 PURL=`ifdh findProject $SAM_PROJECT $SAM_STATION`
185 if [ x$PURL = x ]; then
186 echo "Unable to find url for project ${SAM_PROJECT}."
189 echo "Project url: $PURL"
194 echo "Stopping project."
195 ifdh endProject $PURL
196 if [ $? -eq 0 ]; then
197 echo "Project successfully stopped."
199 echo "Stop project error status $?"
202 # Stash all of the files we want to save in a local
203 # directory with a unique name. Then copy this directory
204 # and its contents recursively.
206 if [ x$LOGDIR != x ]; then
207 OUTPUT_SUBDIR=${CLUSTER}_stop
210 if [ $outfile != $OUTPUT_SUBDIR ]; then
211 mv $outfile $OUTPUT_SUBDIR
214 echo "ifdh cp -r $IFDH_OPT $OUTPUT_SUBDIR ${LOGDIR}/$OUTPUT_SUBDIR"
215 ifdh cp -r $IFDH_OPT $OUTPUT_SUBDIR ${LOGDIR}/$OUTPUT_SUBDIR
217 if [ $stat -ne 0 ]; then
218 echo "ifdh cp failed with status ${stat}."