-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanual_start_services_local.sh
executable file
·145 lines (114 loc) · 3.75 KB
/
manual_start_services_local.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
#!/bin/bash
services=(
"turnstile | ts | 3000"
"customerservice | cs | 3001"
"entry_service | es | 3007"
"catalog_service | cat | 3003"
"orders_service | os | 3004"
"competition_management | comp | 3006"
"payment_service | ps | 3005"
"communication_service | comms | 3008"
"offer_service | off | 3009"
"silverpop_mock | spm | 9001"
)
#addition 4 7 => sum=11
function addition { #(num1, num2)
sum=$(($1 + $2))
}
#$(element "${array[i]}" j) for the (i,j) element in an array described by:
#array=(
# "a0 | a1 | a2"
# "b0 | b1"
# "c0 | c1 | c2 | c3"
# )
#i.e. array[2,3] => element "${array[2]}" 3 => prints "c3"
#i.e. element "${services[0]}" 2 => prints "3000"
function element { #(i, j)
INPUT="$1"
addition $2 1
SUBSTRING=`echo $INPUT| cut -d'|' -f $sum`
echo $SUBSTRING
}
function open_tabs {
for i in ${!services[@]}
do
foo+=(--tab -e "bash -c \"exec bash --init-file $HOME/own_bash_preferences2/tmp_bashrc/.bashrc_replacement_$(element "${services[$i]}" 0).sh\"")
tmp_bashrc
#chmod 777 $HOME/workspace/tmp_bashrc/.bashrc_replacement_$(element "${services[$i]}" 0).sh
done
gnome-terminal "${foo[@]}"
}
#creates temporary replacement .bashrc files for each tab
function tmp_bashrc {
cat << UDK_TERMINATOR > $HOME/own_bash_preferences2/tmp_bashrc/.bashrc_replacement_$(element "${services[$i]}" 0).sh
common_commands=(
"./script/bundle_install"
"bundle exec rake db:reset"
"bundle exec rake db:migrate"
"bundle exec rake db:seed"
"bundle exec rake db:reset RAILS_ENV=test"
"bundle exec rake db:migrate RAILS_ENV=test"
"bundle exec rake db:seed RAILS_ENV=test" #probably not necessary
)
##################################################################### not yet used
#workers must wait for service
workers_commands=(
"cd orders_service && bundle exec rake resque:work QUEUE=orders_service &"
"cd payment_service && bundle exec rake resque:work QUEUE=payment_service &"
"cd communication_service && bundle exec rake resque:work QUEUE=communication_service &"
"cd competition_management && bundle exec rake resque:work QUEUE=competition_management &"
)
function clear_redis {
redis-cli flushdb
}
function start_resque {
resque-web
}
#function start_workers {
#}
#####################################################################
#create the commands to run in each tab
function create_commands {
cmd=""
for item in "\${common_commands[@]}"
do
cmd+="\$item; "
done
if [ "$(element "${services[$i]}" 0)" == "customerservice" ]
then
cmd+="bundle exec rake db:reset RAILS_ENV=test;"
cmd+="bundle exec rake db:migrate RAILS_ENV=test;"
#cmd+="./script/run_for_test_integration.sh; "
cmd+="bundle exec rails s -p 3001 -e testintegration; "
elif [ "$(element "${services[$i]}" 0)" == "catalog_service" ]
then
#wait_for_other_service "competition_management"
wait_for_other_service "$(element "${services[5]}" 2)"
cmd+="bundle exec rails s -p $(element "${services[$i]}" 2); "
else
cmd+="bundle exec rails s -p $(element "${services[$i]}" 2); "
fi
}
function wait_for_other_service { #need to include a time-out
until [[ -n \$(lsof -i :\$1) ]] #check if this is actually the file to check!
do
echo "waiting for service listening on port \$1"
sleep 5
#: #noop
done
}
. /etc/bash.bashrc
. $HOME/.bashrc
. $HOME/.bash_profile
PS1="\${debian_chroot:+(\$debian_chroot)}\u@\h \w\a$ "
echo -en "\033]0;$(element "${services[$i]}" 1)\a"
cd $HOME/workspace/$(element "${services[$i]}" 0)
create_commands
bash -c "\$cmd"
echo "hello, I am $(element "${services[$i]}" 0)"
UDK_TERMINATOR
#terminator, whole line is read and must only contain UDK_TERMINATOR, no spaces.
}
mkdir $HOME/own_bash_preferences2/tmp_bashrc
open_tabs
exit 0