Newer
Older
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
SERVER_NAME="127.0.0.1"
GUNICORN_FILE="/etc/systemd/system/${nameproj}.service"
NGINX_FILE="/etc/nginx/sites-available/${nameproj}"
# parse arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
-s|--servername) SERVER_NAME="$2"; shift ;;
-V|--printvars) declare -p | grep -- '--'|sed -e 's/^declare -- //g' ; exit 0 ;;
-h|*) echo "Usage: ${PROG} [-s|--servername <hostname of webserver>]"; exit 1 ;;
esac
shift
done
if [ -e ${GUNICORN_FILE} -o -e ${NGINX_FILE} ] ; then
echo "A service for ${instr_db} is already installed! Exiting."
exit 1
fi
#GUNICORN_FILE="/etc/systemd/system/$nameproj.service"
/bin/cat <<EOM >$GUNICORN_FILE
[Unit]
Description=gunicorn service
After=network.target
[Service]
User=$USER
Group=www-data
WorkingDirectory=$PWD
ExecStart=$PWD/env/bin/gunicorn --log-level error --timeout 120 --access-logfile $PWD/$nameproj/logs/misc.log --workers 1 --bind unix:$PWD/$nameproj.sock $nameproj.wsgi:application
[Install]
WantedBy=multi-user.target
EOM
#NGINX_FILE="/etc/nginx/sites-available/$nameproj"
touch $NGINX_FILE
/bin/cat <<EOM >$NGINX_FILE
server {
listen 80;
server_name ${SERVER_NAME}; #127.0.0.1;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root $PWD;
}
location / {
include proxy_params;
proxy_pass http://unix:$PWD/$nameproj.sock;
}
}
EOM
rm -rf /etc/nginx/sites-enabled/default
rm -rf /etc/nginx/sites-available/default
ln -s /etc/nginx/sites-available/$nameproj /etc/nginx/sites-enabled