S
S
stvoid2019-06-21 00:12:14
linux
stvoid, 2019-06-21 00:12:14

How to autorun python script in linux?

sh - script:

#!/bin/bash

cd /home/dev/myapp/ \
&& source venv/bin/activate \
&& gunicorn -c gunicorn_config.py run_app:app

There is just run from under the root in the console - everything works ok. The application starts, everything works out ok.
But I don’t understand how to put it on autorun (the provider often reboots servers).
Service script:
[Unit]
Description=My Script Service
After=default.target

[Service]
Type=simple
ExecStart=/root/runserver.sh
Restart=always
User=root

[Install]
WantedBy=multi-user.target

Lies in /lib/systemd/system/runapp.service
Status screen:
5d0bf623e0001703016171.png
At the same time, tell me where how to register the iptables rules also at startup :)
What I read and try to repeat does not work :\

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TyzhSysAdmin, 2019-06-21
@stvoid

1. It's okay for you to read the documentation for the tools you use
- docs.gunicorn.org/en/stable/deploy.html
2. It's okay for you to enter a request in Google to search for deployment methods for the tools you use
- https://bartsimons.me/gunicorn- as-a-systemd-service/
3. It's up to you to study the operating system and its tools
- https://habr.com/ru/company/southbridge/blog/255845/
4. Throw out your script, systemd supervisor and it is not involved by launching scripts, and if you really want to, then don't forget about "environment variables".
But on the other hand, it’s not vlom to come and write a lot of letters on the toaster and at the same time they didn’t even bother to indicate the operating system, specific and not general Linux of which there are 100500 distros and many have their own jokes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question