|
|
@ -47,7 +47,7 @@ SERVICE="app.service" |
|
|
|
|
|
|
|
# Descrição do serviço no Systemctl |
|
|
|
# Systemctl service description |
|
|
|
DESCRIPTION="Django VPS uWSGI Emperor" |
|
|
|
DESCRIPTION="Django VPS" |
|
|
|
|
|
|
|
# Adicionar o certificado digital na aplicação com Certbot. Escreva sim, se já possuir um domínio na internet |
|
|
|
# Apply certbot ssl certificate, hit yes if you already have a domain |
|
|
@ -290,7 +290,7 @@ update_debug() { |
|
|
|
# Install required packages |
|
|
|
install_packages() { |
|
|
|
dnf config-manager --set-enabled crb |
|
|
|
dnf update && |
|
|
|
dnf update -y && |
|
|
|
yum -y install vim && |
|
|
|
yum -y install epel-release && |
|
|
|
yum -y install bind-utils && |
|
|
@ -319,7 +319,6 @@ create_venv() { |
|
|
|
# Install project dependencies |
|
|
|
install_dependencies() { |
|
|
|
/home/$USERNAME/$APP/$VENV/bin/pip3 install --upgrade pip && |
|
|
|
/home/$USERNAME/$APP/$VENV/bin/pip3 install uwsgi && |
|
|
|
/home/$USERNAME/$APP/$VENV/bin/pip3 install -r /home/$USERNAME/$APP/requirements.txt |
|
|
|
if [[ $? -ge 1 ]]; then |
|
|
|
update_step_error "$x" |
|
|
@ -365,57 +364,22 @@ enable_ports() { |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
# Corrigir a configuração inicial do nginx |
|
|
|
# Manage default nginx config file |
|
|
|
manage_default_nginx_file() { |
|
|
|
mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf~ && |
|
|
|
cat > /etc/nginx/nginx.conf <<EOF |
|
|
|
user nginx; |
|
|
|
worker_processes auto; |
|
|
|
error_log /var/log/nginx/error.log; |
|
|
|
pid /run/nginx.pid; |
|
|
|
|
|
|
|
|
|
|
|
include /usr/share/nginx/modules/*.conf; |
|
|
|
|
|
|
|
events { |
|
|
|
worker_connections 1024; |
|
|
|
} |
|
|
|
|
|
|
|
http { |
|
|
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' |
|
|
|
'$status $body_bytes_sent "$http_referer" ' |
|
|
|
'"$http_user_agent" "$http_x_forwarded_for"'; |
|
|
|
|
|
|
|
access_log /var/log/nginx/access.log main; |
|
|
|
|
|
|
|
sendfile on; |
|
|
|
tcp_nopush on; |
|
|
|
tcp_nodelay on; |
|
|
|
keepalive_timeout 65; |
|
|
|
types_hash_max_size 2048; |
|
|
|
|
|
|
|
include /etc/nginx/mime.types; |
|
|
|
default_type application/octet-stream; |
|
|
|
|
|
|
|
include /etc/nginx/conf.d/*.conf; |
|
|
|
} |
|
|
|
EOF |
|
|
|
} |
|
|
|
|
|
|
|
# Criar o arquivo de configurações do NGINX |
|
|
|
# Create nginx config file |
|
|
|
create_nginx_file() { |
|
|
|
cat > /etc/nginx/conf.d/$APP.conf <<EOF |
|
|
|
upstream django { |
|
|
|
server unix:///home/$USERNAME/$APP/mysite.sock; |
|
|
|
} |
|
|
|
|
|
|
|
server { |
|
|
|
listen 80; |
|
|
|
server_name $PUB_IP; |
|
|
|
charset utf-8; |
|
|
|
client_max_body_size 75M; |
|
|
|
server_tokens off; |
|
|
|
|
|
|
|
access_log /var/log/nginx/$APP.access.log; |
|
|
|
error_log /var/log/nginx/$APP.error.log; |
|
|
|
|
|
|
|
location = /favicon.ico { access_log off; log_not_found off;} |
|
|
|
location /media { |
|
|
|
alias /home/$USERNAME/$APP/media; |
|
|
|
} |
|
|
@ -423,8 +387,7 @@ server { |
|
|
|
alias /home/$USERNAME/$APP/static; |
|
|
|
} |
|
|
|
location / { |
|
|
|
uwsgi_pass django; |
|
|
|
include /etc/nginx/uwsgi_params; |
|
|
|
proxy_pass http://unix:/home/$USERNAME/$APP/$APP.sock; |
|
|
|
} |
|
|
|
} |
|
|
|
EOF |
|
|
@ -433,37 +396,6 @@ if [[ $? -ge 1 ]]; then |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
# Criar o arquivo de inicialização do uWSGI |
|
|
|
# Create uwsgi ini file |
|
|
|
create_uwsgi_ini_file() { |
|
|
|
cat > /home/$USERNAME/$APP/uwsgi.ini <<EOF |
|
|
|
[uwsgi] |
|
|
|
chdir = /home/$USERNAME/$APP |
|
|
|
module = $WSGI_FOLDER_NAME.wsgi |
|
|
|
pythonpath = /home/$USERNAME/$APP/$VENV |
|
|
|
master = true |
|
|
|
processes = 10 |
|
|
|
socket = /home/$USERNAME/$APP/mysite.sock |
|
|
|
vacuum = true |
|
|
|
chmod-socket = 666 |
|
|
|
EOF |
|
|
|
if [[ $? -ge 1 ]]; then |
|
|
|
update_step_error "$x" |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
# Criar o modo Emperor do uWSGI |
|
|
|
# Create uWSGI Emperor mode |
|
|
|
criar_emperor_uwsgi() { |
|
|
|
mkdir -p /etc/uwsgi/vassals && |
|
|
|
if [[ ! -f /etc/uwsgi/vassals/uwsgi.ini ]]; then |
|
|
|
ln -s /home/$USERNAME/$APP/uwsgi.ini /etc/uwsgi/vassals |
|
|
|
fi |
|
|
|
if [[ $? -ge 1 ]]; then |
|
|
|
update_step_error "$x" |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
# Cria um serviço no systemctl |
|
|
|
# Create a systemctl service |
|
|
|
create_service_file() { |
|
|
@ -471,17 +403,12 @@ create_service_file() { |
|
|
|
====== |
|
|
|
[Unit] |
|
|
|
Description=$DESCRIPTION |
|
|
|
After=syslog.target |
|
|
|
After=network.target |
|
|
|
|
|
|
|
[Service] |
|
|
|
ExecStart=/usr/local/bin/$SERVICE.sh |
|
|
|
RuntimeDirectory=uwsgi |
|
|
|
Restart=always |
|
|
|
KillSignal=SIGQUIT |
|
|
|
Type=notify |
|
|
|
StandardError=syslog |
|
|
|
NotifyAccess=all |
|
|
|
User=$USERNAME |
|
|
|
WorkingDirectory=/home/$USERNAME/$APP |
|
|
|
ExecStart=/usr/local/bin/$SERVICE.sh |
|
|
|
|
|
|
|
[Install] |
|
|
|
WantedBy=multi-user.target |
|
|
@ -494,10 +421,10 @@ fi |
|
|
|
|
|
|
|
# Criar o script que executa o modo Emperor do uWSGI |
|
|
|
# Create the script called by systemctl service |
|
|
|
create_script_emperor() { |
|
|
|
create_script_executor() { |
|
|
|
cat > /usr/local/bin/$SERVICE.sh <<EOF |
|
|
|
#!/bin/bash |
|
|
|
/home/$USERNAME/$APP/$VENV/bin/uwsgi --emperor /etc/uwsgi/vassals --uid centos --gid centos |
|
|
|
/home/$USERNAME/$APP/$VENV/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/$USERNAME/$APP/$APP.sock $WSGI_FOLDER_NAME.wsgi:application |
|
|
|
EOF |
|
|
|
chmod +x /usr/local/bin/$SERVICE.sh |
|
|
|
if [[ $? -ge 1 ]]; then |
|
|
@ -554,12 +481,9 @@ declare -a commands=( |
|
|
|
"execute_collec_mig_createsup" |
|
|
|
"install_firewall" |
|
|
|
"enable_ports" |
|
|
|
"manage_default_nginx_file" |
|
|
|
"create_nginx_file" |
|
|
|
"create_uwsgi_ini_file" |
|
|
|
"criar_emperor_uwsgi" |
|
|
|
"create_service_file" |
|
|
|
"create_script_emperor" |
|
|
|
"create_script_executor" |
|
|
|
"run_service" |
|
|
|
) |
|
|
|
|
|
|
|