-
Notifications
You must be signed in to change notification settings - Fork 0
/
tfrun.sh
executable file
·106 lines (95 loc) · 2.59 KB
/
tfrun.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/sh
# Temporary directory for run info
#
export SOCKFILE=./.sockfile.$$
cleanup () {
echo "Shutting down" 1>&2
if [ -e $PID ] ; then
kill $PID > /dev/null 2>&1
fi
[ -e $SOCKFILE ] && rm $SOCKFILE
[ ! -z $USE_RELAY ] && [ $USE_RELAY -eq 2 ] && echo "Stoping relay" && stop_relay
exit $STATUS
}
trap cleanup 2 15
# Create the TF directory
#
[ -e $SOCKFILE ] && rm $SOCKFILE
# Source the configuration file
[ -z $TF_HOME ] && export TF_HOME=$(dirname $0|sed 's/bin$//')
[ -z $TF_CONFDIR ] && TF_CONFDIR=$TF_HOME/share/taskfarmer
if [ -e $TF_CONFDIR/$NERSC_HOST.conf ] ; then
. $TF_CONFDIR/$NERSC_HOST.conf
else
echo "The Task Farmer is not currently supported on this system."
exit
fi
# Get the address for the server
#
if [ -z $TF_ADDR ] && [ -z $TF_PORT ] && [ $# -gt 0 ] ; then
export TF_ADDR=$(/sbin/ifconfig $INT|grep 'inet addr'|awk -F: '{print $2}'|sed 's/ .*//')
# Start the server and record the PID
#
if [ $(basename $0) = "tfrun" ] ; then
$TF_HOME/libexec/taskfarmer/tf_server "$@" &
else
base=$(basename $0|sed 's/tf$//')
APP=$(which $base 2>/dev/null) || (echo "Unable to find $base")
[ -z $APP ] && exit
echo "Will run $APP"
$TF_HOME/libexec/taskfarmer/tf_server $APP "$@" &
fi
PID=$!
#
# Wait for the socket file to exist.
#
while [ -d "/proc/$PID" ] && [ ! -e $SOCKFILE ] ; do
sleep 1
done
TF_PORT=$(cat $SOCKFILE)
RETRIES=0
while [ -z $TF_PORT ] ; do
if [ $RETRIES -gt 5 ] ; then
echo "Timed out waiting for server to start. Exiting."
kill $PID
exit
fi
TF_PORT=$(cat $SOCKFILE)
sleep 5
let RETRIES++
done
if [ ! -z $TF_SERVERS ] ; then
echo "$TF_ADDR:$TF_PORT:$PID:$(pwd):$@" >> $TF_SERVERS
fi
else
echo "Server defined. Will contact $TF_ADDR:$TF_PORT"
export EXTERNAL_SERVER=1
[ ! -z $USE_RELAY ] && USE_RELAY=2 && echo "Starting relay" && start_relay
fi
if [ -z $SERVER_ONLY ] || [ ! -z $EXTERNAL_SERVER ] ; then
# Launch the clients
#
run_one
# Get exit status for aprun
#
STATUS=$?
[ ! -z $USE_RELAY ] && [ $USE_RELAY -eq 2 ] && echo "Stoping relay" && stop_relay
else
echo "Starting in server only mode." 1>&2
echo "Cut and paste..." 1>&2
echo "TF_ADDR=$TF_ADDR TF_PORT=$TF_PORT tfrun" 1>&2
wait $PID
STATUS=$?
fi
# Kill the server (just in case)
if [ -z $EXTERNAL_SERVER ] ; then
sleep 1
if [ ! -z $PID ] ; then
echo "Killing Server" 1>&2
[ -d /proc/$PID ] && kill -INT $PID > /dev/null 2>&1
[ -d /proc/$PID ] && kill -INT $PID > /dev/null 2>&1
[ -d /proc/$PID ] && kill $PID > /dev/null 2>&1
fi
[ -e $SOCKFILE ] && rm $SOCKFILE
fi
exit $STATUS