I have a small application written in Python using Flask. Right now I'm running it under nohup, but I'd like to daemonize it. What's the proper way of doing this?
I have a small application written in Python using Flask. Right now I'm running it under nohup, but I'd like to daemonize it. What's the proper way of doing this?
I an running centos with systemd working for all my other services. So I used the same for my flask app
Create a script sh with all my Flask settings
#!/bin/bash
# flask settings
export FLASK_APP=/some_path/my_flask_app.py
export FLASK_DEBUG=0
flask run --host=0.0.0.0 --port=80
Make this script as executable
chmod +x path/of/my/script.sh
Add a systemd service to call this script
/etc/systemd/system/
vim flask.service
[Unit]
Description = flask python command to do useful stuff
[Service]
ExecStart = path/of/my/script.sh
[Install]
WantedBy = multi-user.target
To finish, enable it at boot
systemctl enable flask.service
More info about systemd: https://www.tecmint.com/create-new-service-units-in-systemd/