-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·119 lines (60 loc) · 1.96 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
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
#!/bin/bash
set -e
trap 'current_command=$BASH_COMMAND' DEBUG
trap 'echo "\"${current_command}\" command filed with exit code $?."' EXIT
PWD=$(pwd)
function run_database_migrations(){
echo "Running database migrations"
}
function deploy_updates(){
if [ -f "/etc/systemd/system/api.service" ]; then
echo "Api Service file Found"
# Api status check
API_STATUS=`sudo systemctl status api`
if [ "$API_STATUS" == "active" ]; then
echo "Stoping api service"
sudo systemctl stop api
fi
# install any dependencies
install_depedencies
# perform and database migrations
run_database_migrations
# overwite service file
sudo mv $PWD/api.service /etc/systemd/system/api.service
# reload systemctl deamon
sudo systemctl daemon-reload
# reload-or-start the api service
sudo systemctl reload-or-restart api
sudo systemctl daemon-reload
else
echo "Api Service file not found"
sudo cp $PWD/api.service "/etc/systemd/system/"
# install any dependencies
install_depedencies
# perform and database migrations
run_database_migrations
# reload-or-start the api service
sudo systemctl start api
sudo systemctl daemon-reload
fi
}
function install_depedencies(){
# create a python environment
if [ ! -d $PWD/env ]; then
python3 -m venv env
fi
$PWD/env/bin/pip install -r $PWD/requirements.txt
}
function configure_nginx(){
# copy application server config file to sites-available
sudo cp $PWD/api.conf /etc/nginx/sites-available
# Enble server config
sudo ln -sf /etc/nginx/sites-available/api.conf /etc/nginx/sites-enabled
# reload nginx server
sudo nginx -s reload
}
deploy_updates
# if deploy exits with code 0 then configure nginx
if [ $? -eq 0 ];then
configure_nginx
fi