-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.sh
More file actions
executable file
·172 lines (139 loc) · 4.95 KB
/
config.sh
File metadata and controls
executable file
·172 lines (139 loc) · 4.95 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
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
#!/bin/bash
# config.sh
# Constants
VERSION="Auto-Failover 2.1.1"
AUTHOR="BAMDAD FAKHRAN"
APP_DATE="JANUARY 2019"
TIMEOUT=2
DEFAULT REGION="us-west-2"
APP "VDMS.MSI.VAF"
APP_TITLE="${APP} AUTO CONFIGURATION"
APP_PATH="/opt/failover" # this will be created
OLD_PATH="/etc/fialover" # this will be deleted
APP_PLATFORM="AWS"
DATE=$(date)
D=" "
CFG_PATH="/etc/uplynk"
CFG_OUT="config/config.json"
declare -a CFG_FILES=("${CFG_PATH}"/*.conf)
# Update & install pip
figlet -t "${VERSION}"
echo
echo "${APP_TITLE} » START @ ${DATE}"
echo "${APP_TITLE} » UPDATE"
# apt-get update # execute before this scrip to get object from S3
# apt-get install figlet # install figlet
# apt-get install python-pip # execute before this scrip to get object from S3
# Install boto3 - depends on pip
echo "${APP_TITLE} » BOTO3"
# pip install --upgrade pip # execute before this scrip to get object from S3
# pip install boto3 --upgrade # execute before this scrip to get object from S3
# Install & upgrade awscli - depends on pip
echo "${APP_TITLE} » AWS CLI INIT"
# pip3 install awscli --upgrade # execute before this scrip to get object from $3
# Get the region of current EC2 which running on
REGION=$(curl --connect-timeout $TIMEOUT http://169.254.169.254/latest/meta-data/placement/availability-zone 2>/dev/)
REGION_LEN=${#REGION}
if [ -n "$REGION" ] && [ "$REGION_LEN" -gt 8 ] && [ "$REGION_LEN" -lt 20 ]; then
REGION=${REGION::-1}
else
REGION=${DEFAULT_REGION}
APP_PLATFORM="HW"
fi
echo
echo "${APP_TITLE} » SUMMARY"
echo "${D}Author .......... ${AUTHOR}"
echo "${D}Application ........ ${APP}"
echo "${D}Version ............ ${VERSION}"
echo "${D}Path ............... ${APP_PATH}"
echo "${D}Platform ........... ${APP_PLATFORM}"
echo "${D}Region ............. ${REGION}"
echo
echo "${APP_TITLE} » AWS CLI VERSION"
aws--version
echo
echo "${APP_TITLE} » INFO"
echo "${D}Config Path ........ ${CFG_PATH}"
echo "${D}Config Files :"
for f in "${CFG_PATH}"/*.conf ; do
file="${f##*/}"
cfg_file=$(echo "$file" | cut -d'.' -f1)
echo "${D}${D}${cfg_file}"
done
# Show AWS config
echo
echo "${APP_TITLE} » AWS AUTO CONFIG"
cat ~/.aws/config
# delete failover cron files
# rm /etc/cron.d/vaf-*
CRON_JOBS=$(grep -rlw -e "failover" /etc/cron.d)
for F in "${CRON_JOBS [@]}"; do
rm -f "${F}"
done
for f in "${CFG_PATH}"/*.conf ; do
file="${f##*/}"
cfg_file=$(echo "$file" | cut -d'.' -f1)
echo "${APP_TITLE} » ${cfg_file}"
echo "${D}Directory ...... ${cfg_file}"
echo "${D}Path ........... ${MY_PATH}"
MY_PATH="${APP_PATH}/${cfg_file}"
# delete old install
rm -rf "${OLD_PATH}"
mkdir -p "${MY_PATH}"
cd "${MY_PATH}"
# Create directory structure mkdir -p /.aws
mkdir -p config
mkdir -p logs
mkdir -p util
# cretae/append log file
cat > "$CFG_OUT" <<EOL
{
"Path": "${CFG_PATH}/${cfg_file}.conf",
"Dir": "${cfg_file}"
}
EOL
echo " " > logs/config.log
echo " " > logs/failover.log
echo " " > logs/stdout
echo " " > logs/stderr
echo "${D}Config File .... ${CFG_OUT}"
cat "$CFG_OUT"
# setup permisison
chmod -R 755 logs
# Extract & generate config file for current slicer
echo ""
echo "${APP_TITLE} » FAILOVER MAP CONFIG"
pop=$(hostname | cut -d. -f1)
aws s3api get-object --bucket "vaf-config" --key "failover.tar.gz" "failover.tar.gz" tar -xzf failover.tar.gz
find -name *-type f -delete
rm -rv failover.tar.gz
python config.py
# random 0-59
FLOOR=0
RANGE=59
SYSLOG="${MY_PATH}/logs/stdout"
ERRLOG="${MY_PATH}/logs/stderr"
num=0
while [ "$num" -le $FLOOR ]; do
num=$RANDOM
let "num%= $RANGE"
done
echo "${APP_TITLE} » SELF TEST » CollectMetrics.py"
# python CollectMetrics.py
echo "${APP_TITLE} » SELF TEST » UplynKAPI.py"
# python UplynKAPI.py
echo "${APP_TITLE} » CRON JOBS -------------------------------------"
echo "* * * * * root python ${MY_PATH}/lo-speed-status.py" > "/etc/cron.d/vaf-${cfg_file}-lo-speed-logs"
echo "* * * * * root bash ${MY_PATH}/hs-logs.sh" > "/etc/cron.d/vaf-${cfg_file}-hi-speed-logs"
echo "${num} 2 * * * root bash ${MY_PATH}/s3-upload.sh 1>> ${SYSLOG} 2>> ${ERRLOG}"> "/etc/cron.d/vaf-${cfg_file}-s3-upload"
echo "${num} 3 * * * root bash ${MY_PATH}/upload-logs.sh 1>> ${SYSLOG} 2>> ${ERRLOG}" > "/etc/cron.d/vaf-${cfg_file}-upload-daily-failover-logs"
echo "${num} 4 * * * root bash ${MY_PATH}/house-keeping.sh 1>> ${SYSLOG} 2>> ${ERRLOG}" > "/etc/cron.d/vaf-${cfg_file}-house-keeping"
chmod 755 "/etc/cron.d/vaf-${cfg_file}-lo-speed-logs"
chmod 755 "/etc/cron.d/vaf-${cfg_file}-hi-speed-logs"
chmod 755 "/etc/cron.d/vaf-${cfg_file}-s3-upload"
chmod 755 "/etc/cron.d/vaf-${cfg_file}-upload-daily-failover-logs"
chmod 755 "/etc/cron.d/vaf-${cfg_file}-house-keeping"
ls -la "/etc/cron.d/vaf-${cfg_file}*"
done
DATE=$(date)
echo "${APP_TITLE} » END @ ${DATE}"