-
Notifications
You must be signed in to change notification settings - Fork 0
/
00_create_instance.sh
101 lines (97 loc) · 2 KB
/
00_create_instance.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
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
echo "##########################################"
echo "########## CHECK PREREQUISITE ############"
echo "##########################################"
echo
echo
command_exists () {
command -v $1 >/dev/null 2>&1;
}
if ! command_exists docker;
then
echo "Please install docker"
exit
else
echo "docker installed"
fi
if ! command_exists curl
then
echo "Please install curl"
exit
else
echo "curl installed"
fi
if ! command_exists jq
then
echo "Please install jq"
exit
else
echo "jq installed"
fi
if ! command_exists ifconfig
then
echo "Please install ifconfig"
exit
else
echo "ifconfig installed"
fi
if ! command_exists netstat
then
echo "Please install netstat"
exit
else
echo "netstat installed"
fi
if ! command_exists openssl
then
echo "Please install openssl"
exit
else
echo "openssl installed"
fi
if ! command_exists rsync
then
echo "Please install rsync"
exit
else
echo "rsync installed"
fi
motif="vm.max_map_count"
file="/etc/sysctl.conf"
for file in "${file[@]}"
do
if grep -q "$motif" "$file"; then
echo "The pattern '$motif' is present in the $file."
else
echo "The pattern '$motif' is not present in the $file."
exit 1
fi
done
echo
echo
echo "##########################################"
echo "######### CONFIGURING INSTANCE ###########"
echo "##########################################"
echo
echo
read -p "Enter instance name (no subdirectory name) [ex: production]: " name
name=${name:-production}
SCRIPTDIR="$(pwd)"
# set WORKDIR
WORKDIR="${SCRIPTDIR}/$name"
if [[ ! -d $WORKDIR ]]
then
sudo echo "###### DEPLOY INSTANCE #######"
rsync -r ./ $WORKDIR
sleep 5
cd $WORKDIR
echo "INSTANCE=$name" >> env.sample
sudo bash 01_deploy.sh
cd ..
else
echo "directory/instance name found, deployment stopped"
fi