Systemd
Creare file di servizio: sudo nano /etc/systemd/system/myapp.service
[Unit]
Description=My Python Application
After=network.target
[Service]
User=your_user
Group=your_group
WorkingDirectory=/path/to/your/app
Environment="PATH=/path/to/your/virtualenv/bin"
ExecStart=/path/to/your/virtualenv/bin/python /path/to/your/app/app.py
StandardOutput=file:/path/to/your/app/myscript.log
StandardError=file:/path/to/your/app/myscript_error.log
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.targetDopo aver creato il file, ricarica config: sudo systemctl daemon-reload
Avvia servizio: sudo systemctl start myapp.service
Abilita avvio autom: sudo systemctl enable myapp.service
Controlla stato: sudo systemctl status myapp.service
Vedere log: sudo journalctl -u myapp.service -f
Nohup
esegue un altro comando facendogli ignorare il segnale SIGHUP
nohup _comando_ [_arg1_ [_arg2_ …] ]
ES: nohup python /path/to/your/app.py > myscript.log 2>&1 &