systemd service keep giving me error when start or get status

2024/10/7 2:23:16

I have a python application and I need it to be run as a service, I tried many methods and I was advised to make it as systemd service

I searched and tried some code

here is my unit code

[Unit]
Description=Airnotifier Service
After=network.target[Service]
Type=idle
Restart=on-failure
User=root
ExecStart=python3 /home/airnotifier/airnotifier/app.py[Install]
WantedBy=multi-user.target

and then I run the following commands

sudo systemctl daemon-reload
sudo systemctl enable airnotifier.service
sudo systemctl start airnotifier.service
sudo systemctl status airnotifier.service

the service does not run and I am getting this errors

airnotifier@airnotifier:~$ sudo systemctl status airnotifier.service
● airnotifier.service - Airnotifier ServiceLoaded: loaded (/lib/systemd/system/airnotifier.service; enabled; vendor preset: enabled)Active: failed (Result: exit-code) since Mon 2023-01-09 14:07:38 UTC; 1s agoProcess: 2072 ExecStart=/usr/bin/python3 /home/airnotifier/airnotifier/app.py (code=exited, status=1/FAILURE)Main PID: 2072 (code=exited, status=1/FAILURE)Jan 09 14:07:38 airnotifier systemd[1]: airnotifier.service: Scheduled restart job, restart counter is at 5.
Jan 09 14:07:38 airnotifier systemd[1]: Stopped Airnotifier Service.
Jan 09 14:07:38 airnotifier systemd[1]: airnotifier.service: Start request repeated too quickly.
Jan 09 14:07:38 airnotifier systemd[1]: airnotifier.service: Failed with result 'exit-code'.
Jan 09 14:07:38 airnotifier systemd[1]: Failed to start Airnotifier Service.
Answer

This is the code that works with me

[Unit]
Description=Airnotifier Service[Install]
WantedBy=multi-user.target[Service]
Type=simple
WorkingDirectory=/home/airnotifier/airnotifier
ExecStart=python3 app.py
Restart=always
https://en.xdnf.cn/q/118875.html

Related Q&A

Python 3.5: Print Canvas Text

Could anyone share with me how to print the text of the text widget added to a Canvas object? In the code below, I want the system return the value of "hello" when mouse on the text, however…

What is the most efficient way to match keys from a dictionary to data in text file

Say I have the following dictionary:data=[a 1 : A, b 2 : B, c 3 : C, d 4 : D]and a .txt file which reads:Key a 1 b 2 c 3 d 4 Word as box cow dig(note values are seperated by \t TAB char…

Converting an excel file to a specific Json in python using openpyxl library

I have the Excel data with the format shown in the image preview. How can I convert it into a JSON using Python? Expected Output: file_name = [ { A: Measurement( time=10, X1=1, X2=4 ), B: Measurement(…

Why this algorithm can sort data in descending order

I study python programming and try to sort data in descending order.#sort1 below is successfully sorted but I cannot understand why this happen. Also, data[i], data[data.index(mn)] = data[data.index(m…

Processing.py - Unknown Error on Class Definition

I have no idea how to fix this error. Maybe theres an open parenthesis or quotation mark somewhere before this line?What is wrong with this code?Class Ribbon: # I got an error on this line! def __ini…

How can I implement a stopwatch in my socket Python program

I am creating a very simple ping program in Python that will send 16- 64 bytes of information to a local server, once the server has received all the bytes, it will send back a 1 Byte message back to t…

Making a quiz with shuffled questions

I am wanting to join the Royal Air Force and thought as a good way to prepare I should code myself a quiz about their aircraft.There are 28 aircraft that I have added to the quiz. For example - Where i…

How to create a timer that resets for quiz games?

I trying to create a timer for my quiz game. It should reset after every right question. But problem with my code is that it keeps increasing speed after every time it resets. timeCount = 30 def countd…

Stucking of python multiprocessing.pool

i have multiprocessing script with "pool.imap_unordered". I ran into a problem when the script got stuck but i check CPU usage — nothing happening (by "top" command on ubuntu). Goi…

python: merge two csv files

I have a problem while Im doing my assignment with python. Im new to python so I am a complete beginner.Question: How can I merge two files below?s555555,7 s333333,10 s666666,9 s111111,10 s999999,9and…