12 de janeiro de 2025

Apache Python

Pasta: /etc/apache2/sites-available


Comandos apache:

  • sudo a2ensite site.conf
  • sudo systemctl reload apache2
  • sudo apachectl restart


Arquivo: site.conf


WSGIDaemonProcess venv python-home=/home/project_python/venv python-path=/home/project_python


WSGIProcessGroup venv


WSGIPythonHome /home/project_python/venv


WSGIScriptAlias /url_path /home/project_python/python_file.py/ process-group=venv


<Directory /home/project_python>

  Require all granted

  SetHandler wsgi-script

  Options ExecCGI

  Options +FollowSymLinks

</Directory>


AddType text/html .py


10 de janeiro de 2025

Rodar um script python como serviço no Ubuntu (linux)

 Pasta contendo os serviços:

/etc/systemd/system/

/usr/lib/systemd/system


Exemplo de serviço:

[Unit]

Description=Scheduler Listener

After=network-online.target


[Service]

WorkingDirectory=/home/project_python

ExecStart=/home/project_python/venv/bin/python schedules_listener.py start

Restart=no

RestartSec=60s

KillMode=process

TimeoutSec=infinity

User=inspiron

Group=root


[Install]

WantedBy=multi-user.target


Comandos:

systemctl enable <service file name without .service extension>

systemctl disable <service file name without .service extension>

systemctl daemon-reload

systemctl start <service file name without .service extension>

systemctl stop <service file name without .service extension>


# Verificação do log

sudo journalctl -f -u service_file_name.service