From 7c5d09c2fb36fd5cba5f14269a1675709592b9f5 Mon Sep 17 00:00:00 2001 From: Vineees Date: Thu, 25 Apr 2024 11:47:26 -0300 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=A7=B1=20Crontab=20issue=20solved?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Chaged crontab to run a command on -3:00UTC --- morea_ds/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/morea_ds/settings.py b/morea_ds/settings.py index 6b9ae390..36c22ff5 100755 --- a/morea_ds/settings.py +++ b/morea_ds/settings.py @@ -57,7 +57,7 @@ ROOT_URLCONF = 'morea_ds.urls' CRONJOBS = [ - ('0 0 * * *', 'app.graphs.generateAllMotes24hRaw') + ('0 3 * * *', 'app.graphs.generateAllMotes24hRaw') ] TEMPLATES = [ From e333ac8d8bb6efc21ce956c9ed02cddac811a9e2 Mon Sep 17 00:00:00 2001 From: Vineees Date: Thu, 2 May 2024 19:58:51 -0300 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=9A=A7=20Install=20script=20in=20deve?= =?UTF-8?q?lopment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Solving some bugs and adding new variables. Still remains in WIP --- .env.example | 4 ++-- config/morea.conf | 25 +++++++++++++++++++++++++ install.sh | 42 +++++++++++++++++++++++++++++++++--------- 3 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 config/morea.conf diff --git a/.env.example b/.env.example index 48711b42..8ac5c6cd 100644 --- a/.env.example +++ b/.env.example @@ -5,8 +5,8 @@ DEBUG= #django.db.backends.sqlite3 or django.db.backends.mysql DBTYPE= DBHOST= -#Set your database name -#If you are using sqlite use on DBNAME: BASE_DIR / 'db.sqlite3' +#Set your database name +#MySQL or SQLite3 (Case-sensitive) DBNAME= DBUSER= DBPASSWORD= diff --git a/config/morea.conf b/config/morea.conf new file mode 100644 index 00000000..f69ac220 --- /dev/null +++ b/config/morea.conf @@ -0,0 +1,25 @@ +server { + #LISTEN PORT 80 + listen CHANGE-PORT; + #YOUR DOMAIN OR IP + server_name CHANGE-DOMAIN; + #INCRESE THE MAX TRANSFER + client_max_body_size 32M; + + location / { + + proxy_pass http://127.0.0.1:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + #STATIC LOCATION + location /static/ { + alias CHANGE-STATIC; + } + #MEDIA LOCATION + location /media/ { + alias CHANGE-STATIC; + } + } +} diff --git a/install.sh b/install.sh index 035b6e4e..6583798e 100755 --- a/install.sh +++ b/install.sh @@ -1,30 +1,54 @@ #!/bin/sh + +############################### +# Programa: install.sh +# Desenvolvido por: Vineees (@thevinisouza) +# Data de Criacao: 12/05/2024 +# Versao: 1.0.0 +############################### + python --version sleep 2 - +echo "Antes de Iniciar a Instalação Verique se Já Configurou o .env!" +echo"" echo "Deseja Continuar?" read -p "Press enter to continue""" +echo "Instalando Pacotes!" +sleep 2 +sudo apt install nginx +sudo apt install cron + echo "Criando Enviroment" sleep 2 +# Create environment python3 -m venv env +# Enter environment . env/bin/activate - echo "Enviroment Criado!" -echo "Instalando dependencias!" +echo "Instalando dependencias!" +# Install Deps python3 -m pip install -r ./requirements.txt - echo "Dependencias instaladas!" -echo "Configurando Database!" +echo "Configurando Database!" python3 manage.py makemigrations python3 manage.py migrate +echo "Database Configurada!" -echo "Database Configurado!" echo "Copiando Estaticos" - -cp ./media /var/www/html/Morea/ +read -p “Informe o caminho completo para o diretorio dos estaticos (Ex:/var/www/html/morea/): “ STATICFOLDER +cp ./media $STATICFOLDER python3 manage.py collectstatic --noinput -echo "Estaticos Copiados!" \ No newline at end of file +echo "Estaticos Copiados!" + +echo "Iniciando Configuração do Web Server" +read -p “Porta para hospedar o Serviço: “ NGINXPORT +read -p “Nome no qual o Nginx escutara o request (localhost, domain.net, 192.168.1.1, etc...): “ NGINXDOMAIN +sed -i '3s/CHANGE-PORT/$NGINXPORT/' ./config/morea.conf +sed -i '3s/CHANGE-DOMAIN/$NGINXDOMAIN/' ./config/morea.conf +sed -i '3s/CHANGE-STATIC/$STATICFOLDER/' ./config/morea.conf +cp ./config/morea.conf /etc/nginx/sites-available +ln -s /etc/nginx/sites-available/morea.conf /etc/nginx/sites-enabled/ From e2c200ad803bc3a876618e67dd720ca23c4ec887 Mon Sep 17 00:00:00 2001 From: Vineees Date: Thu, 2 May 2024 20:06:08 -0300 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=90=9B=20Removed=20install.sh=20line?= =?UTF-8?q?=20filter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed the bug where the script read only one line of .conf, the number before the 's' was the problem. --- install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 6583798e..298e6447 100755 --- a/install.sh +++ b/install.sh @@ -47,8 +47,8 @@ echo "Estaticos Copiados!" echo "Iniciando Configuração do Web Server" read -p “Porta para hospedar o Serviço: “ NGINXPORT read -p “Nome no qual o Nginx escutara o request (localhost, domain.net, 192.168.1.1, etc...): “ NGINXDOMAIN -sed -i '3s/CHANGE-PORT/$NGINXPORT/' ./config/morea.conf -sed -i '3s/CHANGE-DOMAIN/$NGINXDOMAIN/' ./config/morea.conf -sed -i '3s/CHANGE-STATIC/$STATICFOLDER/' ./config/morea.conf +sed -i 's/CHANGE-PORT/$NGINXPORT/' ./config/morea.conf +sed -i 's/CHANGE-DOMAIN/$NGINXDOMAIN/' ./config/morea.conf +sed -i 's/CHANGE-STATIC/$STATICFOLDER/' ./config/morea.conf cp ./config/morea.conf /etc/nginx/sites-available ln -s /etc/nginx/sites-available/morea.conf /etc/nginx/sites-enabled/ From fd4557612c3841fb33bed7b02240fd26abca8c81 Mon Sep 17 00:00:00 2001 From: Vineees Date: Thu, 2 May 2024 20:13:57 -0300 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=94=A7=20Added=20socket=20and=20servi?= =?UTF-8?q?ce=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Socket and service files was been added, thay are used to run some proceses on systemd --- config/nameservice.service | 25 +++++++++++++++++++++++++ config/nameservice.socket | 16 ++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 config/nameservice.service create mode 100644 config/nameservice.socket diff --git a/config/nameservice.service b/config/nameservice.service new file mode 100644 index 00000000..8e1ac691 --- /dev/null +++ b/config/nameservice.service @@ -0,0 +1,25 @@ +#/etc/systemd/system/nameservice.service + +[Unit] +Description=gunicorn daemon +Requires=gunicorn.socket +After=network.target + +[Service] +Type=notify +# the specific user that our service will run as +User=someuser +Group=someuser +# another option for an even more restricted service is +# DynamicUser=yes +# see http://0pointer.net/blog/dynamic-users-with-systemd.html +RuntimeDirectory=gunicorn +WorkingDirectory=/home/someuser/applicationroot +ExecStart=/usr/bin/gunicorn applicationname.wsgi +ExecReload=/bin/kill -s HUP $MAINPID +KillMode=mixed +TimeoutStopSec=5 +PrivateTmp=true + +[Install] +WantedBy=multi-user.target diff --git a/config/nameservice.socket b/config/nameservice.socket new file mode 100644 index 00000000..4df123fc --- /dev/null +++ b/config/nameservice.socket @@ -0,0 +1,16 @@ +#/etc/systemd/system/namesocket.socket + +[Unit] +Description=gunicorn socket + +[Socket] +ListenStream=/run/gunicorn.sock +# Our service won't need permissions for the socket, since it +# inherits the file descriptor by socket activation +# only the nginx daemon will need access to the socket +SocketUser=www-data +# Optionally restrict the socket permissions even more. +# SocketMode=600 + +[Install] +WantedBy=sockets.target