forked from jeepapichet/ppdemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestart-demowebapp.sh
executable file
·48 lines (31 loc) · 1.35 KB
/
restart-demowebapp.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
#!/bin/bash -e
main() {
THISDOMAIN="cyberark.local"
PROJECTNAME="ppdemo" #change this if project folder is not ppdemo
echo "-----"
echo "Stop and restart prod/dev webapp containers"
# Start container using docker-compose
docker-compose stop prod-webapp && docker-compose rm -f prod-webapp
docker-compose stop dev-webapp && docker-compose rm -f dev-webapp
docker-compose exec puppet puppet node purge prod-webapp"."$THISDOMAIN
docker-compose exec puppet puppet node purge dev-webapp"."$THISDOMAIN
docker-compose up -d prod-webapp
docker-compose up -d dev-webapp
updatehostsfile $(docker-compose ps -q dev-webapp)
updatehostsfile $(docker-compose ps -q prod-webapp)
}
updatehostsfile() {
local containername="$1"
local processfile=/etc/hosts
local tmpfile=/tmp/${1}.tmp
local knownhostsfile=~/.ssh/known_hosts
conthostname=`docker inspect --format '{{ .Config.Hostname }}' $containername`
contipaddress=`docker inspect --format '{{ .NetworkSettings.Networks.'"$PROJECTNAME"'_default.IPAddress }}' $containername`
echo "---- Update hosts file for $conthostname"
grep -v $conthostname $processfile > $tmpfile
echo -e $contipaddress '\t' $conthostname '\t' $conthostname'.'$THISDOMAIN >> $tmpfile
mv $tmpfile $processfile
echo "---- Remove host from ssh knownhosts"
ssh-keygen -R $conthostname || true
}
main "$@"