-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy_process.sh
118 lines (98 loc) · 3.23 KB
/
deploy_process.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
#!/bin/bash
# NOTE -- node, mysql (include .my.cnf file), nginx, cretbot , git, crontab need to be already installed
# NOTE -- dir init_files should be exist with: .env, rsa_id, nginx_server, nginx_client
git clone https://github.com/yisrael35/rest_imj.git imj_server
git clone https://github.com/yisrael35/react_imj.git imj_client
linux_user=`pwd`
server_path=$linux_user/imj_server/
client_path=$linux_user/imj_client/
cd $server_path
git checkout dev
npm i
init_files_path=$linux_user/init_files
cp $init_files_path/.env $server_path/
cp $init_files_path/rsa_id $server_path/certificates/
mysql -e "CREATE DATABASE imj_db DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
mysql imj_db < $server_path/mysql/migration/data_and_structure.sql
cd $imj_client
git checkout dev
npm run build
cd ..
# ----------------------------------------------------
NGINX_AVAILABLE_VHOSTS='/etc/nginx/sites-available'
NGINX_ENABLED_VHOSTS='/etc/nginx/sites-enabled'
imj_client ='imj_client'
imj_server_rest ='imj_server_rest'
imj_server_ws ='imj_server_ws'
# Create the Nginx config file.
cat > $imj_client <<EOF
server {
root /home/ubuntu/react_imj/build;
index index.html index.htm index.nginx-debian.html;
server_name _ yisraelbar.xyz www.yisraelbar.xyz;
location / {
try_files $uri $uri/ /index.html;
}
}
EOF
echo "imj_client file created"
cat > $imj_server_rest <<EOF
server {
server_name rest-api.yisraelbar.xyz;
location / {
proxy_pass http://localhost:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_send_timeout 300;
}
}
EOF
echo "imj_server_rest file created"
cat > $imj_server_ws <<EOF
server {
server_name ws-api.yisraelbar.xyz;
location / {
proxy_pass http://localhost:3020;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_send_timeout 300;
}
}
EOF
echo "imj_server_rest file created"
cp ./$imj_client $NGINX_AVAILABLE_VHOSTS/$imj_client
echo "imj_client file copied"
rm ./$imj_client
cp ./$imj_server_rest $NGINX_AVAILABLE_VHOSTS/$imj_server_rest
echo "imj_server_rest file copied"
rm ./$imj_server_rest
cp ./$imj_server_ws $NGINX_AVAILABLE_VHOSTS/$imj_server_ws
echo "imj_server_ws file copied"
rm ./$imj_server_ws
# certbot --nginx -d $sub_domain -d www.$sub_domain
ln -s $NGINX_AVAILABLE_VHOSTS/$imj_client $NGINX_ENABLED_VHOSTS/$imj_client
ln -s $NGINX_AVAILABLE_VHOSTS/$imj_server_rest $NGINX_ENABLED_VHOSTS/$imj_server_rest
ln -s $NGINX_AVAILABLE_VHOSTS/$imj_server_ws $NGINX_ENABLED_VHOSTS/$imj_server_ws
echo "file is been pointed"
# certbot -nginx
sudo certbot --nginx -d yisraelbar.xyz -d www.yisraelbar.xyz
sudo certbot --nginx -d rest-api.yisraelbar.xyz -d ws-api.yisraelbar.xyz
/etc/init.d/nginx restart
sudo su
crontab -e
0 12 * * * /usr/bin/certbot renew --quiet
# cronjob
sudo su ubuntu
crontab -e
00 0 * * * /usr/bin/node /home/ubuntu/rest_imj/cron_job/clean_files.js > /home/ubuntu/rest_imj/cron_job/clean_files.log
pm2 start index.js --name server_imj