-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.sh
executable file
·176 lines (168 loc) · 6.03 KB
/
run.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
#!/bin/bash
LOGFILE="isidatainsights.log"
usage() {
checkupgrade
echo "$0 [clean|build|start|stop|status|upload|exportdb|logs]"
exit 0
}
die () {
echo $1
tail -n 10 $LOGFILE
exit 1
}
creategrafanadb() {
docker run --rm -d --name=tempgrafana grafana/grafana-oss && \
sleep 5 && \
docker cp tempgrafana:/var/lib/grafana/grafana.db grafana_extras/grafana.db && \
docker stop tempgrafana && \
chown 472:0 grafana_extras/grafana.db &&
ls -la grafana_extras/grafana.db
}
checkupgrade() {
GIT_VERSION=$(curl -s https://raw.githubusercontent.com/j-sims/idi/main/build_number)
LOCAL_VERSION=$(cat build_number)
if [[ $GIT_VERSION > $LOCAL_VERSION ]]
then
echo ""
echo "****************************************************************"
echo "A new version of Isilon Data Insights is available."
echo ""
echo "To upgrade to the new version run:"
echo ""
echo "bash run.sh upgrade"
echo ""
echo "****************************************************************"
echo ""
fi
}
getclusters() {
[[ -f clusters.toml ]] && die "clusters.toml exists, aborting" && touch clusters.toml
PROMPT="true"
while [ $PROMPT == "true" ]
do
echo ""
echo "Enter then cluster DNS name or IP address"
printf "%s" "Cluster: "
read CLUSTER
echo "Enter the username"
printf "%s" "Username: "
read USER
echo "Enter the password"
printf "%s" "Password: "
read PASSWORD
echo ""
echo "----------------------------------------------------------------"
printf "Cluster Name (or IP): %s\n" "$CLUSTER"
printf "Username: %s\n" "$USER"
printf "Password: %s\n" "$PASSWORD"
echo ""
printf "%s" "Is this correct? (y/n) : "
read VALID
if [[ $VALID == "y" ]]
then
echo "Writing"
echo "[[cluster]]" >> ./clusters.toml
echo "hostname = \"$CLUSTER\"" >> ./clusters.toml
echo "username = \"$USER\"" >> ./clusters.toml
echo "password = \"$PASSWORD\"" >> ./clusters.toml
fi
echo ""
printf "%s" "Add another cluster? (y/n) :"
read ANOTHER
[[ "$ANOTHER" == "y" ]] && PROMPT="true" || PROMPT="false"
done
}
start () {
echo "Starting..."
docker-compose up -d | tee -a $LOGFILE && \
echo "started!"
[[ ! -f .firstrun ]] && \
echo "" && \
echo "Disable the firewall on your Docker Host or add a rule to allow access to Port 3000" && \
echo "" && \
echo "Point your browser to one of the following URLs:" && \
ip a | grep inet | grep -v inet6 | awk '{print$2}' |awk -F\/ '{print$1}' | while read IP; do echo "http://$IP:3000/dashboards"; done && \
#ifconfig | grep inet | grep -v inet6 | grep -v 127.0.0.1 | awk '{print$2}' | while read IP; do echo "http://$IP"; done
echo "" && \
echo "First Time Login: " && \
echo "username: admin" && \
echo "password: admin" && \
touch .firstrun
}
[[ $1 == "" ]] && usage
case $1 in
clean)
echo "This process will DELETE the InfluxDB removing all stats and starting clean."
echo ""
echo "To confirm you intend to REMOVE EVERYTHING in the database please type DELETE at the prompt."
echo ""
printf "%s" "Prompt: "
read ACTION
if [[ "$ACTION" == "DELETE" ]]
then
docker-compose down >>$LOGFILE 2>&1
rm -rf backups/* >>$LOGFILE 2>&1
rm -rf influxdb/data/* >>$LOGFILE 2>&1
rm -rf grafana_extras/grafana.db >>$LOGFILE 2>&1
rm -rf clusters.toml >>$LOGFILE 2>&1
docker images | grep $(basename `pwd`) | awk '{print$3}' | xargs docker rmi >>$LOGFILE 2>&1
docker rmi golang >>$LOGFILE 2>&1
docker rmi grafana/grafana-oss >>$LOGFILE 2>&1
docker rmi influxdb:1.8 >>$LOGFILE 2>&1
docker rmi isidatainsights-client >>$LOGFILE 2>&1
docker rmi ubuntu:22.04 >>$LOGFILE 2>&1
rm -f .firstrun
rm -f $LOGFILE
echo "Cleanup Complete"
fi
;;
build)
echo "starting container build, may take a few minutes."
echo "details logged in $LOGFILE"
docker-compose build >>$LOGFILE 2>&1 && \
docker-compose pull >>$LOGFILE 2>&1 && \
cd client && \
docker build -t isidatainsights-client . >>$LOGFILE 2>&1 && \
cd .. && \
echo "Completed building containers..." && \
[[ -f grafana_extras/grafana.db ]] || creategrafanadb >>$LOGFILE 2>&1 && \
getclusters && \
start || die "Error, checking logs"
;;
start)
checkupgrade
start
;;
stop)
checkupgrade
docker-compose down | tee -a $LOGFILE;;
status)
checkupgrade
docker-compose ps | tee -a $LOGFILE;;
exportdb)
echo "exportdb"
docker run --rm -ti --network isidatainsights -v $(pwd)/backups:/backups isidatainsights-client;;
upload)
checkupgrade
echo "upload"
docker run --rm -ti --network isidatainsights -e UPLOAD=true -v $(pwd)/backups:/backups isidatainsights-client;;
logs)
echo "#####################################################################"
echo "# tailing logs, CTRL+C to exit #"
echo "#####################################################################"
docker-compose logs -f --tail=5;;
upgrade)
echo "upgrade"
git pull && \
docker-compose build >>$LOGFILE 2>&1 && \
docker-compose pull >>$LOGFILE 2>&1 && \
cd client && \
docker build -t isidatainsights-client . >>$LOGFILE 2>&1 && \
cd .. && \
[[ -f grafana_extras/grafana.db ]] || creategrafanadb >>$LOGFILE 2>&1 && \
docker-compose down && \
docker-compose up -d && \
echo "Upgrade Successful" || echo "Error upgrading"; tail -n 20 $LOGFILE;;
*)
usage;;
esac