-
Notifications
You must be signed in to change notification settings - Fork 0
/
gsecontrol_single
executable file
·266 lines (245 loc) · 6.84 KB
/
gsecontrol_single
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
263
264
265
266
#!/bin/bash
#
# Shell script that controls GSE daemons
#
# $Source: /cvsroot/anita-lite/gse/gsecontrol,v $
# $Date: 2003/12/05 20:43:22 $
# $Revision: 1.6 $
# $Author: predragm $
#
. ./local.config
PATH=$DAEMONTOOLS_DIR:$PATH
SVC=$DAEMONTOOLS_DIR/svc
# List of daemons we'll supervise
RECEIVE=$PWD/tcp/receive.sh # Level 1
PROCESS=$PWD/tcp/process_data.pl # Level 2
CLEARLINK=$PWD/clearlink.pl # Level 3,4,5
LINKFEED=$PWD/linkfeed.pl # Level 3,4,5
UNPACKD=$PWD/unpack/unpackd # Level 3,4,5
function mkbashrun()
{
file=$1
niceLevel=$2
daemon=$3
flag=$4
echo \#!/bin/bash >$file
echo "exec 2>&1" >>$file
echo exec nice -$niceLevel $daemon $flag >>$file
chmod a+x $file
}
function mkperlrun()
{
file=$1
niceLevel=$2
daemon=$3
flag=$4
echo \#!/bin/bash >$file
echo "exec 2>&1" >>$file
echo exec nice -$niceLevel perl -I $PWD $daemon $flag >>$file
chmod a+x $file
}
function mklogrun()
{
file=$1
logdir=$2
mkdir -p $logdir
echo \#!/bin/bash >$file
echo exec $DAEMONTOOLS_DIR/multilog t n100000 s9999999 $logdir >>$file
chmod a+x $file
}
function mklinkfeed()
{
niceLevel=$1
daemon=$2
type=$3
dir=$PWD/services/linkfeed_$type
mkdir -p $dir/log
mkperlrun $dir/run $niceLevel $daemon "$type $LINK_DIR"
mklogrun $dir/log/run $LOG_DIR/linkfeed_$type
}
function mkunpack()
{
niceLevel=$1
daemon=$2
type=$3
fmt=$4
buff=$5
monstep=$6
rm -rf /tmp/unpackd_fifo_$type
mknod /tmp/unpackd_fifo_$type p
mkdir -p $TELEM_DIR/$type
dir=$PWD/services/unpackd3_$type
mkdir -p $dir/log
flag="-f $PWD/$fmt.fmt -b $buff -m/tmp/anita_monitor_$type.txt -u $monstep -d\`cat $PWD/currentdb\` /tmp/unpackd_fifo_$type"
mkbashrun $dir/run $niceLevel $daemon "$flag"
mklogrun $dir/log/run $LOG_DIR/unpackd3_$type
dir=$PWD/services/unpackd4_$type
mkdir -p $dir/log
flag="-f $PWD/$fmt.fmt -b $buff -m/tmp/anita_monitor_$type.txt -u $monstep -t $TELEM_DIR/$type /tmp/unpackd_fifo_$type"
mkbashrun $dir/run $niceLevel $daemon "$flag"
mklogrun $dir/log/run $LOG_DIR/unpackd4_$type
dir=$PWD/services/unpackd5_$type
mkdir -p $dir/log
flag="-f $PWD/$fmt.fmt -b $buff -m/tmp/anita_monitor_$type.txt -u $monstep -d\`cat $PWD/currentdb\` -t $TELEM_DIR/$type /tmp/unpackd_fifo_$type"
mkbashrun $dir/run $niceLevel $daemon "$flag"
mklogrun $dir/log/run $LOG_DIR/unpackd5_$type
}
#
# See how we were called.
#
case "$1" in
run)
# Start in correct run mode by making link to appropriate
# directories
case "$2" in
1)
if [ ! -e $FILENAME_PIPE ]; then
ln -s /dev/null $FILENAME_PIPE
fi
ln -sf $PWD/services/receive $PWD/active_services
;;
2)
$0 run 1
if [ ! -p $FILENAME_PIPE ]; then
rm -f $FILENAME_PIPE
mkfifo $FILENAME_PIPE
fi
ln -sf $PWD/services/process $PWD/active_services
;;
[3-5])
$0 run 2
ln -sf $PWD/services/clearlink $PWD/active_services
ln -sf $PWD/services/linkfeed_los $PWD/active_services
ln -sf $PWD/services/linkfeed_fast_tdrss $PWD/active_services
ln -sf $PWD/services/linkfeed_slow_tdrss $PWD/active_services
ln -sf $PWD/services/linkfeed_iridium $PWD/active_services
ln -sf $PWD/services/linkfeed_openport $PWD/active_services
ln -sf $PWD/services/unpackd${2}_los $PWD/active_services
ln -sf $PWD/services/unpackd${2}_sip_hr $PWD/active_services
ln -sf $PWD/services/unpackd${2}_sip_lr $PWD/active_services
ln -sf $PWD/services/unpackd${2}_iridium $PWD/active_services
ln -sf $PWD/services/unpackd${2}_openport $PWD/active_services
;;
*)
echo "Usage: $0 run [1-5]"
exit
esac
;;
stop)
# Stop run levels
case "$2" in
1)
dir=$PWD/active_services/receive
if test -d $dir; then
if test -d $dir/log; then
$SVC -dx $dir/log
fi
$SVC -dx $dir
rm -f $dir
fi
;;
2)
ln -sf /dev/null $FILENAME_PIPE
dir=$PWD/active_services/process
if test -d $dir; then
if test -d $dir/log; then
$SVC -dx $dir/log
fi
$SVC -dx $dir
rm -f $dir
fi
;;
[3-5])
for dir in $PWD/active_services/unpackd${2}_* $PWD/active_services/*link* ; do
if test -d $dir; then
if test -d $dir/log; then
$SVC -dx $dir/log
fi
$SVC -dx $dir
rm -f $dir
fi
done
;;
*)
# Stop all daemons
for dir in $PWD/active_services/[a-zA-Z]*; do
if test -d $dir; then
if test -d $dir/log; then
$SVC -dx $dir/log
fi
$SVC -dx $dir
rm -f $dir
fi
done
;;
esac
;;
setup)
# Make sure we're terminated beforehand
killall -q svscan
killall -q supervise
# Configure all directories and links
mkdir -p $PWD/services/receive/log
cp -a $RECEIVE $PWD/services/receive/run
mklogrun $PWD/services/receive/log/run $LOG_DIR/receive
mkdir -p $PWD/services/process/log
mkperlrun $PWD/services/process/run 0 $PROCESS
mklogrun $PWD/services/process/log/run $LOG_DIR/process
mkdir -p $PWD/services/clearlink/log
mkperlrun $PWD/services/clearlink/run 0 $CLEARLINK "$AGE_CUT $LINK_DIR"
mklogrun $PWD/services/clearlink/log/run $LOG_DIR/clearlink
mklinkfeed 1 $LINKFEED los
mklinkfeed 1 $LINKFEED fast_tdrss
mklinkfeed 1 $LINKFEED slow_tdrss
mklinkfeed 1 $LINKFEED iridium
mklinkfeed 1 $LINKFEED openport
mkunpack 5 $UNPACKD los los 9000 5
mkunpack 5 $UNPACKD sip_hr sip_hr 9000 1
mkunpack 5 $UNPACKD sip_lr sip_lr 255 1
mkunpack 5 $UNPACKD iridium sip_lr 255 1
mkunpack 5 $UNPACKD openport sip_hr 9000 5
$0 newdb
# Finally, start svscan
mkdir -p $PWD/active_services
$0 prime
;;
prime)
svscan $PWD/active_services &
;;
newdb)
HOUR=`date -u +%k`
if [ $HOUR -lt 5 ]
then SUFFIX=a
elif [ $HOUR -lt 11 ]
then SUFFIX=b
elif [ $HOUR -lt 17 ]
then SUFFIX=c
else SUFFIX=d
fi
DATE=`date -u +%m%d`
DBNAME=${DBBASE}_$DATE$SUFFIX
./makedb $DBNAME
;;
rotate)
for dir in $PWD/active_services/*link* $PWD/active_services/unpackd* ; do
if test -d $dir; then
$SVC -d $dir
fi
done
$0 newdb
for dir in $PWD/active_services/unpackd* $PWD/active_services/*link* ; do
if test -d $dir; then
$SVC -u $dir
fi
done
;;
terminate)
$0 stop
killall -q svscan
killall -q supervise
rm -rf active_services services
;;
*)
echo "Usage: $0 {run n|stop [n]|setup|terminate|prime|newdb|rotate}"
exit
esac