https://tecadmin.net/setup-autorun-python-script-using-systemd/
Question – How to autorun a Python script using systemd. How to create own systemd service using Python script. How to configure Python script to start as systemd. How to manage Python service with systemctl?
Use this tutorial to run your Python script as system service under systemd. You can easily start, stop or restart your script using systemctl command. This will also enable to autorun Python script on system startup.
Step 1 – Dummy Python Application
First of all, I have used a dummy Python script which listens on a specified port. Edit a Python file as following
and add following content for dummy, You can use your own Python script as per requirements.
Step 2 – Create Service File
Now, create a service file for the systemd as following. The file must have .serviceextension under /lib/systemd/system/ directory
and add the following content in it. Change Python script filename ad location. Also update the Description.
Step 3 – Enable Newly Added Service
Your system service has been added to your service. Let’s reload the systemctl daemon to read new file. You need to reload this deamon each time after making any changes in in .service file.
Now enable the service to start on system boot, also start the service using the following commands.
Step 4 – Start/Start/Status new Service
Finally check the status of your service as following command.
Use below commands to stop, start and restart your service manual.
'C Lang > Python Program Diary' 카테고리의 다른 글
nginx - gunicorn - supervisor로 파이썬 디플로이하기 (0) | 2019.08.16 |
---|---|
python에서 dict형은 순서를 보장하는가? (0) | 2019.08.13 |
라이브러리 읽기 대상 디렉토리를 추가하기 : sys.path.append, os.path.dirname (0) | 2019.07.26 |
python에서 페키지 만들어서 test.pypi에 배포 후 import해서 사용해보기 (0) | 2019.07.05 |
python에서 root 디렉토리 설정하기★★★ (0) | 2019.06.28 |