-
Notifications
You must be signed in to change notification settings - Fork 0
/
VALET_balancer_executor
executable file
·45 lines (32 loc) · 2.23 KB
/
VALET_balancer_executor
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
#!/bin/bash
search_line_number=$(grep -n "master-instance" terraform/terraform.tfstate | cut -f1 -d:) #Get line number, after master information starts
MASTER_NODE_IP_PUBLIC=$(tail -n +$search_line_number terraform/terraform.tfstate | grep "access_ip_v4" | awk -F ': "' '{print $2}' | head -c -3) #Get public IP of master node
SSH_PATH_MASTER=$(awk '/private_key_path/{getline; print}' terraform/vars.tf | awk -F ' = "' '{print $2}' | head -c -2) #Get path to SSH key to master node
RC_FILE_PATH="/path/to/rc/file.sh"
### Logdate variables ###
month_short=$(date +%b)
day=$(date +%d)
timestamp=$(date +%T)
logtime="$month_short$day $timestamp"
function VALET_status_check {
local status_key_word_transmitted
status_key_word_transmitted=$(ssh -n -o StrictHostKeyChecking=no -i $SSH_PATH_MASTER centos@$MASTER_NODE_IP_PUBLIC VALET_balancer_parser) #Request cluster status from parser on master node
if [ -z "$status_key_word_transmitted" ]; then #Check for empty variable as answer
echo "$logtime Status request sends empty variable please check services on master node"
elif [ "$status_key_word_transmitted" == "" ]; then #Check for empty string as answer
echo "$logtime Status request sends empty string please check services on master node"
elif [ "$status_key_word_transmitted" == "start" ]; then #Check for keyword start as answer
echo "$logtime Status request sends command to start a new node"
sh start_up_new_node $RC_FILE_PATH
elif [ "$status_key_word_transmitted" == "stop" ]; then #Check for keyword stop as answer
echo "$logtime Status request sends command to stop a node"
sh stop_node $RC_FILE_PATH
elif [ "$status_key_word_transmitted" == "stay" ]; then #Check for keyword stay as answer
echo "$logtime Status request sends command to stay with the current number of nodes"
elif [ "$status_key_word_transmitted" == "none" ]; then #Check for keyword none as answer
echo "$logtime Status request sends information, that the .VALET_status file in /home/centos/ does not exist"
else #Default fallback if undefined behaviour occurs
echo "$logtime Status reqest sends an undefined command: $status_key_word_transmitted"
fi
}
VALET_status_check #Call function