#1. clone repo and cd
cd /home/user/
git clone $1
REPO=$1
FOLDER=${REPO%.*}
FOLDER=${FOLDER##*/}
cd $FOLDER
# crea .env
#improve to make random str to secret key
cat > /home/user/$FOLDER/.env << EOL
SECRET_KEY=some_secreat_key
ALLOWED_HOSTS=localhost,$3, www.$3
DEBUG=True
DB_NAME=$2
DB_USER=$2
HOST=some_host
PORT=some port
DB_PASSWORD=some_password
PRODUCTION=True
EOL
#asigna permisos a la carpeta de la app
cd ..
chown -R user:user $FOLDER
#Creación de socket
cat > /etc/systemd/system/gunicorn_$2.socket << EOL
[Unit]
Description=$2 socket"
[Socket]
ListenStream=/run/gunicorn_$2.sock
[Install]
WantedBy=sockets.target
EOL
APP=${FOLDER//-/_}
#creación de servicio
cat > /etc/systemd/system/gunicorn_$2.service << EOL
[Unit]
Description=$2 daemon
Requires=gunicorn_$2.socket
After=network.target
[Service]
User=user
Group=www-data
WorkingDirectory=/home/user/$FOLDER
ExecStart=/usr/local/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn_$2.sock $APP.wsgi:application
[Install]
WantedBy=multi-user.target
EOL
#inicia y habilita el servicio
systemctl daemon-reload
systemctl stop gunicorn_$2.socket
systemctl start gunicorn_$2.socket
systemctl daemon-reload
systemctl enable gunicorn_$2.socket
#habilita salida http
#bad practice, shoud ln to www/var/html and nginx go to www/var/html inestead of home/user/proyect
cat > /etc/nginx/sites-available/$3 << EOL
server {
server_name $3 www.$3;
location = /favicon.ico { access_log off; log_not_found off; }
location /staticfiles/ {
root /home/user/$FOLDER;
}
location /media/ {
root /home/user/$FOLDER;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn_$2.sock;
}
}
EOL
ln -s /etc/nginx/sites-available/$3 /etc/nginx/sites-enabled
nginx -t
systemctl restart nginx
certbot --nginx -d $3 -d www.$3
It depends, some people use virtualenvs, so you need to install gunicorn in each project.
this might help, just change dependencies install to fit your os.
In my case, I deploy multiple projects with the same python and dependencies install without virtualenv and made a little script, need improvement but it's enough to pull some project from a repo and install the app.
It take 3 params, repository, db name and domain name.
db name equals to project name in my case.
El vie., 11 sept. 2020 a las 4:44, Kasper Laudrup (<laudrup@stacktrace.dk>) escribió:
Hi Giovanni,
On 11/09/2020 12.24, Giovanni Silva wrote:
> No...
> I want to access www.aidacomunicacao.com.br
> <http://www.aidacomunicacao.com.br> and I hope see the django webpage
>
Then don't listen on port 81, but use the default port 80 for
non-encrypted HTTP traffic.
Kind regards,
Kasper Laudrup
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9b32d1a8-b947-6b48-0e93-aab3dae8470a%40stacktrace.dk.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHRQUHni7xh79yr0k4TJRCxRmtkLMgf7Xv57ktKB%2BsFL0WOqxw%40mail.gmail.com.
No comments:
Post a Comment