0

I am trying to start a Python3 script on boot. The script listens to a 433 MHz receiver for remote button presses, then publishes an mqtt message for matching button codes.

The python code works just fine from the command line:

python3 /home/pi/433/433rcv.py

When I run:

systemctl status 433rcv.service

I get lots of errors:

pi@raspberrypi:/lib/systemd/system $ systemctl status 433rcv.service
? 433rcv.service
   Loaded: error (Reason: Invalid argument)
   Active: inactive (dead)

Jul 17 10:53:13 raspberrypi systemd[1]: 433rcv.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Jul 17 10:54:49 raspberrypi systemd[1]: [/lib/systemd/system/433rcv.service:1] Unknown section 'unit'. Ignoring.
Jul 17 10:54:49 raspberrypi systemd[1]: [/lib/systemd/system/433rcv.service:5] Unknown section 'service'. Ignoring.
Jul 17 10:54:49 raspberrypi systemd[1]: 433rcv.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Jul 17 11:00:56 raspberrypi systemd[1]: [/lib/systemd/system/433rcv.service:1] Unknown section 'unit'. Ignoring.
Jul 17 11:00:56 raspberrypi systemd[1]: [/lib/systemd/system/433rcv.service:5] Unknown section 'service'. Ignoring.
Jul 17 11:00:56 raspberrypi systemd[1]: 433rcv.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Jul 17 11:02:22 raspberrypi systemd[1]: [/lib/systemd/system/433rcv.service:1] Unknown section 'unit'. Ignoring.
Jul 17 11:02:22 raspberrypi systemd[1]: [/lib/systemd/system/433rcv.service:5] Unknown section 'service'. Ignoring.
Jul 17 11:02:22 raspberrypi systemd[1]: 433rcv.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.

I have little experience writing services files. While I appreciate the flexibility of the systemd method, it sure does make it difficult to start a script on boot.

Here is my services file:

[unit]
Description=Run the 433Mhz Receiver
After=multi-user.target

[service]
type=idle
ExecStart=/usr/bin/python3 /home/pi/433/rcv.py -q &

[Install]
WantedBy=multi-user.target

So, if anyone can see my problem, assistance would be greatly appreciated. (Extra info: I ran dos2unix to make sure that wasn't the problem. No difference).

2

I guess it's Unit and Service, with capitals. Probably same thing with Type

  • Also you never launch a service detached. They just run. – kwasmich Jul 17 '18 at 16:01
0

Beside correct writing the statements as @eftshift0 stated in his answer there may be some other quirks.

You set Type=idle. man systemd.service says:

Behavior of idle is very similar to simple; however, actual execution of the service binary is delayed until all active jobs are dispatched. This may be used to avoid interleaving of output of shell services with the status output on the console. Note that this type is useful only to improve console output, it is not useful as a general unit ordering tool, and the effect of this service type is subject to a 5s time-out, after which the service binary is invoked anyway.

You execute the script on the command line and there is a console for output. But starting a script as service there is no console for output except you have explicitly programmed it in the script. I don't believe it or what console you are looking at to see the output from your script at startup? Or parameter -q on your script means --quiet? Then you also don't need Type=idle. So I suggest to use Type=simple (the default).

With ExecStart=/usr/bin/python3 /home/pi/433/rcv.py -q & you use job control to send it to the background with &. Don't do that. Services are running by default in the background. So if you using job control with & systemd may loose control of its job so it is possible you cannot use systemctl for 433rcv.service the right way.

I suggest your unit should look like this:

[Unit]
Description=Run the 433Mhz Receiver
After=multi-user.target

[Service]
Type=simple   # or omit this line, its default
ExecStart=/usr/bin/python3 /home/pi/433/rcv.py -q

[Install]
WantedBy=multi-user.target
0

Thanks to all who helped. Someday I hope to be able to answer some questions near your level.

I should have noticed that the error was "Unknown section 'unit'" and 'service', but not 'Install'. Now it's hammered home that the correct spelling is 'Unit' and 'Service'.

I also understand, no '&'. Makes sense since a service is by definition running in the background. And, yes, I am using argparse, and -q squelches all console output of the script.

At any rate, Ingo's post above fixed everything, and I learned more today.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.