P
P
pthon2021-02-12 08:03:01
linux
pthon, 2021-02-12 08:03:01

How to tell the system that the service has started?

Hello, I want to run a python script as a service, the script starts and runs, but the system shows it in the activating state, which is why it constantly restarts, maybe

systemd[1]: rpi-rf.service: Failed with result 'timeout'.
.
How to tell the system that the script has started and is running?
.service:
# systemd unit file for the Python Demo Service


[Unit]

# Human readable name of the unit
Description=Python rpi-rf_receiver


[Service]

# Command to execute when the service is started
ExecStart=/usr/bin/python3 /usr/local/lib/rpi-rf/rpi-rf_receive

# Disable Python's buffering of STDOUT and STDERR, so that output from the
# service shows up immediately in systemd's logs
Environment=PYTHONUNBUFFERED=1

# Automatically restart the service if it crashes
Restart=on-failure
RestartSec=5

# Our service will notify systemd once it is up and running
Type=notify

# Use a dedicated user to run our service
User=root


[Install]

# Tell systemd to automatically start this service when the system boots
# (assuming the service is enabled)
WantedBy=default.target

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
pthon, 2021-02-12
@pthon

A more correct way

from systemd.daemon import notify, Notification

# Send READY=1
notify(Notification.READY)

A
Alexey Cheremisin, 2021-02-12
@leahch

Change Type=notifytoType=simple

D
Dr. Bacon, 2021-02-12
@bacon

Why is the Type=notify option added?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question