Service files: Difference between revisions
No edit summary |
No edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= Making | === Making a systemd service file === | ||
See: https://blog.miguelgrinberg.com/post/running-a-flask-application-as-a-service-with-systemd | See: https://blog.miguelgrinberg.com/post/running-a-flask-application-as-a-service-with-systemd | ||
Line 5: | Line 5: | ||
Useful: https://containersolutions.github.io/runbooks/posts/linux/debug-systemd-service-units/ | Useful: https://containersolutions.github.io/runbooks/posts/linux/debug-systemd-service-units/ | ||
$ sudo nano /etc/systemd/system/myflaskapp.service | |||
< | <pre> | ||
[Unit] | [Unit] | ||
Description=<a description of your application> | Description=<a description of your application> | ||
Line 20: | Line 20: | ||
[Install] | [Install] | ||
WantedBy=multi-user.target | WantedBy=multi-user.target | ||
</ | </pre> | ||
When the service file is new or changed, you need (one time) to: | When the service file is new or changed, you need (one time) to: | ||
$ sudo systemctl daemon-reload | |||
Then you can: | Then you can: | ||
$ sudo systemctl start myflaskapp | |||
$ sudo systemctl status myflaskapp | |||
$ sudo systemctl restart myflaskapp | |||
$ sudo systemctl stop myflaskapp | |||
'''Then finally''' when you see that start works (checking status, checking that it actually is running , etc) | '''Then finally''' when you see that start works (checking status, checking that it actually is running , etc) | ||
$ sudo systemctl enable myflaskapp | |||
Will make the "service" auto start when the pi restarts. | Will make the "service" auto start when the pi restarts. | ||
Line 42: | Line 42: | ||
To view the log file (errors): | To view the log file (errors): | ||
$ sudo journalctl -u myflaskapp -f | |||
You can find documentation here: | |||
https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html | |||
[[Category:Cookbook]] |
Latest revision as of 14:33, 19 November 2024
Making a systemd service file
See: https://blog.miguelgrinberg.com/post/running-a-flask-application-as-a-service-with-systemd
Useful: https://containersolutions.github.io/runbooks/posts/linux/debug-systemd-service-units/
$ sudo nano /etc/systemd/system/myflaskapp.service
[Unit] Description=<a description of your application> After=network.target [Service] User=<username> WorkingDirectory=<path to your app> ExecStart=<app start command> Restart=always [Install] WantedBy=multi-user.target
When the service file is new or changed, you need (one time) to:
$ sudo systemctl daemon-reload
Then you can:
$ sudo systemctl start myflaskapp $ sudo systemctl status myflaskapp $ sudo systemctl restart myflaskapp $ sudo systemctl stop myflaskapp
Then finally when you see that start works (checking status, checking that it actually is running , etc)
$ sudo systemctl enable myflaskapp
Will make the "service" auto start when the pi restarts.
To view the log file (errors):
$ sudo journalctl -u myflaskapp -f
You can find documentation here:
https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html