-
Notifications
You must be signed in to change notification settings - Fork 22
/
workerStartup.sh
executable file
·169 lines (145 loc) · 3.96 KB
/
workerStartup.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
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
#!/bin/bash
function setRoot
{
local this
local lls
local link
local bin
this="${BASH_SOURCE-$0}"
while [ -h "$this" ]; do
lls=`ls -ld "$this"`
link=`expr "$lls" : '.*-> \(.*\)$'`
if expr "$link" : '.*/.*' > /dev/null; then
this="$link"
else
this=`dirname "$this"`/"$link"
fi
done
# convert relative path to absolute path
bin=`dirname "$this"`
script=`basename "$this"`
bin=`cd "$bin"; pwd`
#this="$bin/$script"
echo "$bin";
}
function isLinux
{
test "$(uname)" = "Linux"
}
function isMac
{
test "$(uname)" = "Darwin"
}
function isCygwin
{
os="$(uname)"
test "${os:0:6}" = "CYGWIN"
}
function xEnabled
{
if isCygwin
then
return false
fi
(xterm -e "") 2>&1 > /dev/null
}
#--------------------------------------------init--------------------------------------
ROOT=${ROOT="$(setRoot)"}
osName="$(uname)"
if [ "$osName" = Darwin ] || [ "${osName:0:6}" = CYGWIN ] || [ "$osName" = Linux ]
#if [ "$osName" = Darwin ] || [ "$osName" = Linux ]
then
true
else
echo "Unsupported OS. Currently only Linux, Mac and Windows with \
Cygwin are supported"
#echo "Unsupported OS. Currently only Linux and Mac OS \
#are supported"
exit;
fi
CLASSPATH_SEPARATOR=":"
if isLinux || isCygwin
then
workerHosts=$(cat "$ROOT/conf/workers.conf" | sed 's/[ \t]\+//g' | \
sed 's/#.*$//g' | sed '/^$/d' | sed 's/:[0-9]\+$//g' | sort | uniq)
workers=$(cat "$ROOT/conf/workers.conf" | sed 's/[ \t]\+//g' | \
sed 's/#.*$//g' | sed '/^$/d')
if isCygwin
then
CLASSPATH_SEPARATOR=";"
fi
elif isMac
then
workerHosts=$(cat "$ROOT/conf/workers.conf" | sed -E 's/[ ]+//g' | \
sed -E 's/#.*$//g' | sed -E '/^$/d' | sed -E 's/:[0-9]+//g' | sort | uniq)
workers=$(cat "$ROOT/conf/workers.conf" | sed -E 's/[ ]+//g' | \
sed -E 's/#.*$//g' | sed -E '/^$/d')
fi
#--------------------------------------------start workers--------------------------------------
echo "Starting workers"
terminal=xterm
titleOption=-title
if ! [ -z "$(which gnome-terminal)" ]
then
terminal=gnome-terminal
titleOption=-t
#elif ! [ -z "$(which konsole)" ]
#then
# terminal=konsole
fi
for worker in $workers
do
if isMac
then
host=$(echo $worker | sed -E 's/:[0-9]+$//g')
port=$(echo $worker | sed -E 's/^[^:]+://g')
else
host=$(echo $worker | sed 's/:[0-9]\+$//g')
port=$(echo $worker | sed 's/^[^:]\+://g')
fi
if isLinux || isCygwin
then
if ! xEnabled
then
(exec ssh $host "cd ${ROOT}; source env/bin/activate; pip install -r requirements.txt; cd VideoSearchEngine; python video_util_worker.py ${host}:$port" 2>&1 | \
sed "s/^/$host:$port\\$ /g") &
else
${terminal} ${titleOption} "Worker: $host:$port. Do not close this window when worker is running." -e \
"bash -c \"ssh $host \\\"cd ${ROOT}; source env/bin/activate; pip install -r requirements.txt; cd VideoSearchEngine; python video_util_worker.py ${host}:$port\\\" | \
sed \\\"s/^/$host:$port\\\\$ /g\\\" \" " &
fi
else
#mac
osascript -e "tell app \"Terminal\"
do script \"echo -e \\\"\\\\033]0;Worker: $host:$port. Do not close this window when worker is running.\\\\007\\\"; ssh $host \\\"cd ${ROOT}; source env/bin/activate; pip install -r requirements.txt; cd VideoSearchEngine; python video_util_worker.py ${host}:$port \\\"\"
end tell"
fi
done
#outputStyle="X"
#if ! xEnabled
#then
# outputStyle="T"
#fi
javaOptions=
if isCygwin
then
javaOptions=-Djline.terminal=jline.UnixTerminal
fi
#--------------------------------------------start server--------------------------------------
echo "Finish starting workers, now starting the server"
cd "$ROOT"
port_list=""
for worker in $workers
do
if isMac
then
host=$(echo $worker | sed -E 's/:[0-9]+$//g')
port=$(echo $worker | sed -E 's/^[^:]+://g')
else
host=$(echo $worker | sed 's/:[0-9]\+$//g')
port=$(echo $worker | sed 's/^[^:]\+://g')
fi
port_list+=$host:$port
port_list+=","
done
exec python VideoSearchEngine/VideoDistributer.py --video_path clips/bunny_clip.mp4 --port_list ${port_list}