-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdeploy.sh
executable file
·58 lines (53 loc) · 2.09 KB
/
deploy.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
user=ubuntu
host=ec2-xx-xxx-xxx-xxx.us-east-1.compute.amazonaws.com
[email protected]:SpartaSystems/social-media-monitor.git
script_dir=$(dirname $0)
temp=orion
source ${script_dir}/../update_creds.sh # contains update_creds() to update credential files
function execute() {
while [ "$1" != "" ]; do
case $1 in
-h| help ) echo "Usage: deploy.sh (-d|-c)"
echo "-d : deploy latest master branch to production"
echo "-c : update config files with credentials (not stored in vcs)"
;;
-d| deploy ) echo "deploying..."
git clone ${repo} ${temp}
update_creds ${script_dir}/${temp}/monitor/configuration # directory that has config files in it
rm -rf ${temp}/.git* ${temp}/deploy.sh
ssh -i "orion.pem" ${user}@${host} << EOF
rm -rf ${temp}.backup
mv ${temp} ${temp}.backup
EOF
scp -r -i "orion.pem" ${temp} ${user}@${host}:~
rm -rf ${temp}
ssh -i "orion.pem" ${user}@${host} << EOF
pidfile=~/pid.txt
cd ~/orion/webapp/frontend && npm install && npm run build
if [ -f \$pidfile ]; then
echo "killing processes based on pid.txt"
while read line; do
kill -9 \$line
done < \$pidfile
rm \$pidfile 2> /dev/null
fi
cd ~/orion/webapp/backend && npm install
nohup npm start 1> webapp-out.log 2>&1 & echo \$! >> \$pidfile
cd ~/orion/monitor && npm install
nohup node index.js 1> monitor-out.log 2>&1 & echo \$! >> \$pidfile
cat \$pidfile
EOF
echo "deployed successfully."
;;
-c| config ) update_creds ${script_dir}
;;
esac
shift
done
}
if [ $# -eq 0 ]; then
execute -h
else
execute $@
fi