-
Notifications
You must be signed in to change notification settings - Fork 1
/
l2
executable file
·262 lines (250 loc) · 6.44 KB
/
l2
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/bin/bash
# This script can start and stop the three main components of the L2 system:
# the client, convert, and manager scripts. It tracks the PGIDs of these
# processes in the file $PGID. When starting, it also ensures that the
# necessary files and directory structures are present, and, if not, constructs
# them.
# Do not delete this weird line
# It sets the option which assigns new pgid's to backgrounded pipelines
set -m
# Organization of locations. Set directory structure here:
BS=$HOME/BufferScripts # Path to the BufferScripts repository
FILESYSTEM=/raid # Buffer filesystem
L1=$FILESYSTEM/data/l1 # Directory for raw data
LOGDIR=$BS/log # Central location for L2 log files
ZDAB=$HOME/zdab # Directory for post-L2 zdab files
MAC=$BS/mac # Directory for conversion macros
GRIDREADY=$FILESYSTEM/data/l2 # Output directory for finished products
RATENV=/opt/env/latest.sh # Location of rat_env.sh script
DONTDELETE=$BS/dontdelete # directory for writing deletion locks
DATA=$FILESYSTEM/data/l1 # normal data directory
TESTDATA=$HOME/testbuilderdata # test data directory
CHOPPER=$HOME/stonehenge/stonehenge.sh # Location of Stonehenge program
REDISHOST=192.168.80.128 # Location of monitoring redis db
#----------------------------------------------------------
# Below this line we specify the relative paths to different components of
# the L2 system. This should not need to be edited to reflect local installations.
SERVERFL=$BS/buffer/served.txt
SERVERLS=$BS/buffer/ls.txt
CLIENT=$BS/buffer/client
STONELOG=$LOGDIR/stone.log
CLIENTLOG=$LOGDIR/client.log
JOBQUEUE=$BS/buffer/jobs
CONVERT=$BS/buffer/convert
CONVERTLOG=$LOGDIR/convert.log
MANAGER=$BS/buffer/manager
MANAGERLOG=$LOGDIR/manager.log
PGIDFILE=$BS/pgid.txt
MONITOR=$BS/monitor.py
#-----------------------------------------------------------
# Prints the help text
printhelp() {
echo -e 'This is the L2 Trigger Master Script.'
echo -e 'It takes the following arguments:'
echo -e '-a \t \t Start all scripts'
echo -e '-k \t \t Stop all scripts'
echo -e '-s [string] \t Start script [string]'
echo -e '-z [string] \t Stop script [string]'
echo -e '-h \t \t Print this help text'
}
# This function parses the PGID file
parsepgid(){
if [ ! -f $PGIDFILE ]
then
clientpgid=0
convertpgid=0
managerpgid=0
else
count=0
while read -r line
do
let count++
case "$count" in
1)
clientpgid=$line
;;
2)
convertpgid=$line
;;
3)
managerpgid=$line
;;
*)
echo Invalid PGID file!
exit 1
;;
esac
done < $PGIDFILE
fi
}
# This function updates the PGID file
# Should only be called if parsepgid has already been called
writepgid(){
echo -e $clientpgid '\n'$convertpgid '\n'$managerpgid > $PGIDFILE
}
# This function starts individual scripts
# If script already running, prints message
startprocess(){
parsepgid
case "$1" in
"client")
if [ "$clientpgid" -eq 0 ]
then
$CLIENT $L1 $STONELOG $CHOPPER $JOBQUEUE $MAC \
$GRIDREADY $DATA $TESTDATA $SERVERFL $SERVERLS $REDISHOST $ZDAB \
2>> $CLIENTLOG | python $MONITOR L2-client >> $CLIENTLOG 2>&1 &
clientpgid=$(jobs -lp | tail -n 1)
else
echo Client process was already running.
fi
;;
"convert")
if [ "$convertpgid" -eq 0 ]
then
$CONVERT $JOBQUEUE $CONVERTLOG $MAC $RATENV $REDISHOST \
$ZDAB 2>> $CONVERTLOG | \
python $MONITOR L2-convert >> $CONVERTLOG 2>&1 &
convertpgid=$(jobs -lp | tail -n 1)
else
echo Convert process was already running.
fi
;;
"manager")
if [ "$managerpgid" -eq 0 ]
then
$MANAGER $FILESYSTEM $L1 $DONTDELETE $MAC 2>> $MANAGERLOG | \
python $MONITOR L1-delete >> $MANAGERLOG 2>&1 &
managerpgid=$(jobs -lp | tail -n 1)
else
echo Manager process was already running.
fi
;;
*)
echo -e 'Invalid process name passed\n'
echo -e 'Valid options are client, convert, manager\n'
exit 1
;;
esac
writepgid
}
# This function kills individual scripts and their decendents
# If the script is not running, prints message.
stopprocess(){
parsepgid
case "$1" in
"client")
if [ $clientpgid -ne 0 ]
then
kill -- -$clientpgid
clientpgid=0
else
echo Client process was not running.
fi
;;
"convert")
if [ $convertpgid -ne 0 ]
then
kill -- -$convertpgid
convertpgid=0
else
echo Convert process was not running.
fi
;;
"manager")
if [ $managerpgid -ne 0 ]
then
kill -- -$managerpgid
managerpgid=0
else
echo Manager process was not running.
fi
;;
*)
echo -e 'Invalid process name passed.\n'
echo -e 'Valid options are client, convert, and manager.\n'
exit 1
;;
esac
writepgid
}
# This function sets up the L2 scripts to start
start_all(){
parsepgid
if [[ "$clientpgid" -eq 0 && "$convertpgid" -eq 0 && "$managerpgid" -eq 0 ]]
then
echo Preparing file structure...
if [ ! -d $LOGDIR ]
then
mkdir $LOGDIR
fi
if [ ! -d $ZDAB ]
then
mkdir $ZDAB
fi
if [ ! -d $MAC ]
then
mkdir $MAC
fi
if [ ! -d $L1 ]
then
mkdir $L1
fi
if [ ! -d $JOBQUEUE ]
then
mkdir $JOBQUEUE
fi
if [ ! -d $DONTDELETE ]
then
echo No DONTDELETE folder! Aborting!
exit 0
fi
echo File structure prepared.
echo Starting level 2 scripts...
startprocess client
startprocess convert
startprocess manager
else
echo Some processes were already running. Please stop all scripts before \
using the -a option. If you do not want to stop running processes, \
you can start the processes one at a time using the -s option.
fi
}
stop_all(){
echo Killing L2 processes
stopprocess client
stopprocess convert
stopprocess manager
}
# MAIN
if [[ $# -eq 0 ]]
then
printhelp
fi
while getopts "h?aks:z:" opt
do
case "$opt" in
h)
printhelp
exit 0
;;
a)
start_all
exit 0
;;
k)
stop_all
exit 0
;;
s)
name=$OPTARG
startprocess $name
;;
z)
name=$OPTARG
stopprocess $name
;;
*)
echo -e 'Invalid argument\n'
;;
esac
done