-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·78 lines (69 loc) · 1.88 KB
/
start.sh
File metadata and controls
executable file
·78 lines (69 loc) · 1.88 KB
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
#!/bin/bash
my_dir="$(dirname "$0")"
source $my_dir/config.sh
if [[ $wd == "" ]]; then
echo "Please specify working dir in config.sh"
exit 1
fi
startnode=
connectstring=
fast=false
if [[ $1 == "-f" ]]; then
connectstring=`cat .connectstring`
if [[ $connectstring == "" ]]; then
echo "No previous execution. Please start without '-f' flag."
exit 1
fi
fast=true
fi
if [[ $fast == false ]]; then
echo "" > .workingnodes
fi
function async_start {
echo "-- $1 - Connecting to $connectstring..."
output=`$ssh $username@$1 "bash $wd/start.sh $connectstring" 2>&1`
if [[ $output == "" ]] || [[ $output =~ port[[:space:]]([[:digit:]]+) ]] ; then
echo "-- $1 - Started with connection to first node"
echo $1 >> .workingnodes
else
echo -e "-- $1 - Error\n$output"
fi
}
while read host; do
if [[ $host =~ ^#.* ]] || [[ $host == '' ]]; then
continue
fi
if [[ $startnode == "" ]]; then
startnode=$host
continue
fi
if [[ $startnode == $host ]]; then
continue
fi
if [[ $fast == true ]]; then
# If fast mode is set, do not start all nodes except the main node
break
fi
if [[ $connectstring == '' ]]; then
# Start first instance
echo "-- $host - Starting up"
startres=`$ssh $username@$host "bash $wd/start.sh" 2>&1 </dev/null`
if [[ $startres =~ port[[:space:]]([[:digit:]]+) ]]; then
echo "-- $host - Started on port ${BASH_REMATCH[1]}"
connectstring="$host:${BASH_REMATCH[1]}"
echo "$connectstring" > .connectstring
echo $host >> .workingnodes
else
echo "-- $host - Could not start as first node."
echo "$startres"
fi
else
# Connect instance to existing one
async_start $host &
fi
done < nodes.txt
# Wait for all startup processes to finish
wait
# Start main program
echo "-- $startnode - Starting main node"
$ssh $username@$startnode "$wd/start.sh $connectstring run"