-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_nginx_conf.sh
executable file
·58 lines (51 loc) · 1.61 KB
/
add_nginx_conf.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
#!/bin/bash
# This script serves to make a LayersBox Adapter aware of a new backend service.
if [ $# -le 1 ]
then
sn=$1
echo "The new service is called '$sn' ."
elif [ $# -eq 0 ]
then
echo "No arguments passed to setup script. Aborting..."
exit 1
else
echo "Too many service names specified! Aborting..."
exit 1
fi
tc=/usr/local/openresty/conf
td=$tc/services
echo "The path for all service subdirectories is set to $td ."
out=$(docker ps -a | grep -c adapter-data)
if [ $out -gt 0 ]
then
echo "Adapter data container found. Checking whether the service has been added already..."
nsv=$(docker exec adapter ls $tc)
if [[ $nsv != *"services"* ]]
then
docker exec adapter mkdir -p $td/
fi
nsv=$(docker exec adapter ls $td)
if [[ $nsv == *"$sn"* ]]
then
echo "Previous configuration detected. Deleting old configuration..."
docker exec adapter rm -rf $td/$sn
echo "Recreating path for new dir..."
else
echo "No previous configuration for this service found. Proceeding with setup..."
echo "Creating path for new dir..."
fi
docker exec adapter mkdir -p $td/$sn/
sf="nginx.adapted.conf"
if [ -f ./services/$sn/$sf ]
then
echo "Service's nginx.adapted.conf found."
echo "Copying service's nginx.adapted.conf to newly created path $nsv..."
docker cp ./services/$sn/${sf} adapter-data:$td/$sn
localhost_ip="$(ifconfig en0 inet | grep "inet " | awk -F'[: ]+' '{ print $2 }')"
docker exec adapter sed -i s#dockerhost#http://$localhost_ip#g $td/$sn/$sf
else
echo "No configuration file found! The file must be named 'nginx.adapted.conf'. Aborting..."
exit 1
fi
echo "Finished."
fi