Professional Documents
Culture Documents
Linux Services
Linux Services
To configure a program as a service, we must create a file inside /etc/systemd/system called like this: my_app.service .
Inside it, we can write something like this:
[Unit]
Description=My python web application
[Service]
ExecStart=/usr/bin/python3 /opt/code/my_app.py
# Executed before ExecStart
ExecStartPre=/opt/code/configure_db,sh
# Executed after ExecStart
ExecStartPost=/opt/code/email_status.sh
Restart=always
Now we can say to systemctl that there is a new service: systemctl daemon-reload . Finally, we can start the service like this:
systemctl start my_app .