Escribiendo un servicio para un script python con ambiente virtual
1. Escribiendo el archivo .service
vim /etc/systemd/system/hipy.service
2. Gestión del Servicio
systemctl stop hipy.service
systemctl start hipy.service
systemctl daemon-reload
# systemctl status hipy.service
● hipy.service - Ejemplo de Script python en ambiente virtual como servicio
Loaded: loaded (/etc/systemd/system/hipy.service; disabled; preset: enabled)
Active: active (running) since Tue 2024-05-07 10:58:19 -05; 12min ago
Main PID: 2385 (python)
Tasks: 6 (limit: 1113)
Memory: 34.9M (peak: 35.1M)
CPU: 2.929s
CGroup: /system.slice/hipy.service
└─2385 /home/myuser/python/myEnv/bin/python /home/myuser/python/main.py
May 07 10:58:19 py systemd[1]: Started hipy.service - Ejemplo de Script python como servicio.
May 07 10:58:20 py python[2385]: INFO: Started server process [2385]
May 07 10:58:20 py python[2385]: INFO: Waiting for application startup.
May 07 10:58:20 py python[2385]: INFO: Application startup complete.
May 07 10:58:20 py python[2385]: INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)
# systemctl enable hipy.service
Created symlink /etc/systemd/system/multi-user.target.wants/hipy.service → /etc/systemd/system/hipy.service.
root@py:/etc/systemd/system# systemctl status hipy.service
● hipy.service - Ejemplo de Script python en ambiente virtual como servicio
Loaded: loaded (/etc/systemd/system/hipy.service; enabled; preset: enabled)
Active: active (running) since Tue 2024-05-07 10:58:19 -05; 14min ago
Main PID: 2385 (python)
Tasks: 6 (limit: 1113)
Memory: 34.9M (peak: 35.1M)
CPU: 3.186s
CGroup: /system.slice/hipy.service
└─2385 /home/myuser/python/myEnv/bin/python /home/myuser/python/main.py
May 07 10:58:19 py systemd[1]: Started hipy.service - Ejemplo de Script python como servicio.
May 07 10:58:20 py python[2385]: INFO: Started server process [2385]
May 07 10:58:20 py python[2385]: INFO: Waiting for application startup.
May 07 10:58:20 py python[2385]: INFO: Application startup complete.
May 07 10:58:20 py python[2385]: INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)