Compare commits
4 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac551141cb | ||
|
|
e1b9669d1a | ||
|
|
cb9d26e82c | ||
|
|
693bfbe6f9 |
2 changed files with 16 additions and 92 deletions
|
|
@ -35,7 +35,7 @@ SERVICE="app.service"
|
||||||
|
|
||||||
# Descrição do serviço no Systemctl
|
# Descrição do serviço no Systemctl
|
||||||
# Systemctl service description
|
# 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
|
# 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
|
# Apply certbot ssl certificate, hit yes if you already have a domain
|
||||||
|
|
|
||||||
106
run.sh
106
run.sh
|
|
@ -47,7 +47,7 @@ SERVICE="app.service"
|
||||||
|
|
||||||
# Descrição do serviço no Systemctl
|
# Descrição do serviço no Systemctl
|
||||||
# Systemctl service description
|
# 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
|
# 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
|
# Apply certbot ssl certificate, hit yes if you already have a domain
|
||||||
|
|
@ -290,7 +290,7 @@ update_debug() {
|
||||||
# Install required packages
|
# Install required packages
|
||||||
install_packages() {
|
install_packages() {
|
||||||
dnf config-manager --set-enabled crb
|
dnf config-manager --set-enabled crb
|
||||||
dnf update &&
|
dnf update -y &&
|
||||||
yum -y install vim &&
|
yum -y install vim &&
|
||||||
yum -y install epel-release &&
|
yum -y install epel-release &&
|
||||||
yum -y install bind-utils &&
|
yum -y install bind-utils &&
|
||||||
|
|
@ -319,7 +319,6 @@ create_venv() {
|
||||||
# Install project dependencies
|
# Install project dependencies
|
||||||
install_dependencies() {
|
install_dependencies() {
|
||||||
/home/$USERNAME/$APP/$VENV/bin/pip3 install --upgrade pip &&
|
/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
|
/home/$USERNAME/$APP/$VENV/bin/pip3 install -r /home/$USERNAME/$APP/requirements.txt
|
||||||
if [[ $? -ge 1 ]]; then
|
if [[ $? -ge 1 ]]; then
|
||||||
update_step_error "$x"
|
update_step_error "$x"
|
||||||
|
|
@ -365,57 +364,22 @@ enable_ports() {
|
||||||
fi
|
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
|
# Criar o arquivo de configurações do NGINX
|
||||||
# Create nginx config file
|
# Create nginx config file
|
||||||
create_nginx_file() {
|
create_nginx_file() {
|
||||||
cat > /etc/nginx/conf.d/$APP.conf <<EOF
|
cat > /etc/nginx/conf.d/$APP.conf <<EOF
|
||||||
upstream django {
|
|
||||||
server unix:///home/$USERNAME/$APP/mysite.sock;
|
|
||||||
}
|
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name $PUB_IP;
|
server_name $PUB_IP;
|
||||||
charset utf-8;
|
charset utf-8;
|
||||||
client_max_body_size 75M;
|
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 {
|
location /media {
|
||||||
alias /home/$USERNAME/$APP/media;
|
alias /home/$USERNAME/$APP/media;
|
||||||
}
|
}
|
||||||
|
|
@ -423,8 +387,7 @@ server {
|
||||||
alias /home/$USERNAME/$APP/static;
|
alias /home/$USERNAME/$APP/static;
|
||||||
}
|
}
|
||||||
location / {
|
location / {
|
||||||
uwsgi_pass django;
|
proxy_pass http://unix:/home/$USERNAME/$APP/$APP.sock;
|
||||||
include /etc/nginx/uwsgi_params;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
@ -433,37 +396,6 @@ if [[ $? -ge 1 ]]; then
|
||||||
fi
|
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
|
# Cria um serviço no systemctl
|
||||||
# Create a systemctl service
|
# Create a systemctl service
|
||||||
create_service_file() {
|
create_service_file() {
|
||||||
|
|
@ -471,17 +403,12 @@ create_service_file() {
|
||||||
======
|
======
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=$DESCRIPTION
|
Description=$DESCRIPTION
|
||||||
After=syslog.target
|
After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/usr/local/bin/$SERVICE.sh
|
|
||||||
RuntimeDirectory=uwsgi
|
|
||||||
Restart=always
|
|
||||||
KillSignal=SIGQUIT
|
|
||||||
Type=notify
|
|
||||||
StandardError=syslog
|
|
||||||
NotifyAccess=all
|
|
||||||
User=$USERNAME
|
User=$USERNAME
|
||||||
|
WorkingDirectory=/home/$USERNAME/$APP
|
||||||
|
ExecStart=/usr/local/bin/$SERVICE.sh
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
@ -494,10 +421,10 @@ fi
|
||||||
|
|
||||||
# Criar o script que executa o modo Emperor do uWSGI
|
# Criar o script que executa o modo Emperor do uWSGI
|
||||||
# Create the script called by systemctl service
|
# Create the script called by systemctl service
|
||||||
create_script_emperor() {
|
create_script_executor() {
|
||||||
cat > /usr/local/bin/$SERVICE.sh <<EOF
|
cat > /usr/local/bin/$SERVICE.sh <<EOF
|
||||||
#!/bin/bash
|
#!/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
|
EOF
|
||||||
chmod +x /usr/local/bin/$SERVICE.sh
|
chmod +x /usr/local/bin/$SERVICE.sh
|
||||||
if [[ $? -ge 1 ]]; then
|
if [[ $? -ge 1 ]]; then
|
||||||
|
|
@ -554,12 +481,9 @@ declare -a commands=(
|
||||||
"execute_collec_mig_createsup"
|
"execute_collec_mig_createsup"
|
||||||
"install_firewall"
|
"install_firewall"
|
||||||
"enable_ports"
|
"enable_ports"
|
||||||
"manage_default_nginx_file"
|
|
||||||
"create_nginx_file"
|
"create_nginx_file"
|
||||||
"create_uwsgi_ini_file"
|
|
||||||
"criar_emperor_uwsgi"
|
|
||||||
"create_service_file"
|
"create_service_file"
|
||||||
"create_script_emperor"
|
"create_script_executor"
|
||||||
"run_service"
|
"run_service"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue