-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathLAUNCH.sh
executable file
·177 lines (150 loc) · 4.7 KB
/
LAUNCH.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
170
171
172
173
174
175
176
177
#!/bin/bash
GREEN="\\033[1;32m"
DEFAULT="\\033[0;39m"
RED="\\033[1;31m"
ROSE="\\033[1;35m"
BLUE="\\033[1;34m"
WHITE="\\033[0;02m"
YELLOW="\\033[1;33m"
CYAN="\\033[1;36m"
. ./PSSHENV/bin/activate
isredis=`screen -ls | egrep '[0-9]+.Redis_PSSH' | cut -d. -f1`
isserver=`screen -ls | egrep '[0-9]+.Server_PSSH' | cut -d. -f1`
function helptext {
echo -e $YELLOW"
"$DEFAULT"
This script launch: (Inside screen Daemons)"$CYAN"
- All Redis in memory servers.
- Flask server.
Usage: LAUNCH.sh
[-l | --launchAuto]
[-k | --killAll]
[-h | --help]
"
}
function launching_redis {
conf_dir="${PSSH_HOME}/configs"
redis_dir="${PSSH_HOME}/redis/src/"
redis_port=`cat $conf_dir/config.cfg | grep 'redis_port' | cut -d " " -f 3`
redis_db=`cat $conf_dir/config.cfg | grep 'redis_db' | cut -d " " -f 3`
echo $redis_db
screen -dmS "Redis_PSSH"
sleep 0.1
echo -e $GREEN"\t* Launching PSSH Redis Servers"$DEFAULT
if [ "$redis_db" == "kvrocks" ]; then
screen -S "Redis_PSSH" -X screen -t $redis_port bash -c 'cd '${PSSH_HOME}'; ./kvrocks/build/kvrocks -c '$conf_dir/$redis_port'.conf ; read x'
else
screen -S "Redis_PSSH" -X screen -t $redis_port bash -c $redis_dir'redis-server '$conf_dir/$redis_port'.conf ; read x'
fi
sleep 0.
}
function shutting_down_redis {
conf_dir="${PSSH_HOME}/configs"
redis_port=`cat $conf_dir/config.cfg | grep 'redis_port' | cut -d " " -f 3`
redis_dir=${PSSH_HOME}/redis/src/
bash -c $redis_dir'redis-cli -p '$redis_port' SHUTDOWN'
sleep 0.1
}
function checking_redis {
conf_dir="${PSSH_HOME}/configs"
redis_port=`cat $conf_dir/config.cfg | grep 'redis_port' | cut -d " " -f 3`
flag_redis=0
redis_dir=${PSSH_HOME}/redis/src/
bash -c $redis_dir'redis-cli -p '$redis_port' PING | grep "PONG" &> /dev/null'
if [ ! $? == 0 ]; then
echo -e $RED"\t6379 not ready"$DEFAULT
flag_redis=1
fi
sleep 0.1
return $flag_redis;
}
function launch_redis {
if [[ ! $isredis ]]; then
launching_redis;
else
echo -e $RED"\t* A Redis_PSSH screen is already launched"$DEFAULT
fi
}
function launching_server {
screen -dmS "Server_PSSH"
sleep 0.1
echo -e $GREEN"\t* Launching PSSH server"$DEFAULT
# LAUNCH CORE MODULE
screen -S "Server_PSSH" -X screen -t "server" bash -c "cd ${PSSH_HOME}/bin; ./passive_ssh_server.py; read x"
sleep 0.1
}
function launch_server {
if [[ ! $isserver ]]; then
launching_server;
else
echo -e $RED"\t* A Server_PSSH screen is already launched"$DEFAULT
fi
}
function killall {
if [[ $isredis || $isgflask ]]; then
echo -e $GREEN"\t* Gracefully closing PSSH ..."$DEFAULT
kill $isserver
echo -e $GREEN"\t* $isserver killed."$DEFAULT
echo -e $GREEN"\t* Gracefully closing redis servers ..."$DEFAULT
shutting_down_redis;
kill $isredis
sleep 0.2
else
echo -e $RED"\t* No screen to kill"$DEFAULT
fi
}
function launch_all {
helptext;
launch_redis;
launch_server;
}
#If no params, display the menu
[[ $@ ]] || {
helptext;
options=("Redis" "Killall")
menu() {
echo "What do you want to Launch?:"
for i in ${!options[@]}; do
printf "%3d%s) %s\n" $((i+1)) "${choices[i]:- }" "${options[i]}"
done
[[ "$msg" ]] && echo "$msg"; :
}
prompt="Check an option (again to uncheck, ENTER when done): "
while menu && read -rp "$prompt" numinput && [[ "$numinput" ]]; do
for num in $numinput; do
[[ "$num" != *[![:digit:]]* ]] && (( num > 0 && num <= ${#options[@]} )) || {
msg="Invalid option: $num"; break
}
((num--)); msg="${options[num]} was ${choices[num]:+un}checked"
[[ "${choices[num]}" ]] && choices[num]="" || choices[num]="+"
done
done
for i in ${!options[@]}; do
if [[ "${choices[i]}" ]]; then
case ${options[i]} in
Redis)
launch_redis;
;;
Killall)
killall;
;;
esac
fi
done
exit
}
while [ "$1" != "" ]; do
case $1 in
-l | --launchAuto ) launch_all;
;;
-k | --killAll ) helptext;
killall;
;;
-h | --help ) helptext;
exit
;;
* ) helptext
exit 1
esac
shift
done