0

I made a test with a basic python script /home/pi/Documents/sample.py:

print("hello word")

then I wrote a service script /etc/systemd/system/my_boot.service:

[unit]
Description=Raspberry Pi My test
After=network.target
 
[Service]
Type=idle
ExecStart=/usr/bin/python3 /home/pi/Documents/sample.py
User=pi
 
[Install]
WantedBy=default.target

Then I Typed:

systemctl daemon-reload
systemctl enable my_boot.service
systemctl start my_boot.service

When I reboot, nothing happens although I can see the name of the service displayed in the boot sequence. I tried with python instead of python3. When I use the rc.local instead of systemd 'Hello world' is displayed correctly at boot. My config is Console mode automatic login. I'm using Wifi and SSH.

2 Answers 2

0

you can check to see if it ran by using: systemctl status my_boot and I would expect it to show that it ran and is terminated. You could also amend the python code to create a file and write to that, say /tmp/my_boot.log and check that.

I have an on-boot service that writes to a database on another Pi.

0

See StandardOutput in man systemd.exec; this defaults to journal which means you should find "hello word" in sudo journalctl -u my_boot. This may or may not end up also going to the console, and in looking through /lib/systemd/system/rc-local.service it's not clear why that would work from there.

In any case, your best bet is probably:

[Service]
StandardOutput=journal+console

There's no plain console.

I suspect there's a bit of an XY problem since using the system console to convey information to ??? is not a good methodology.

You may also want to try adding After=rc-local.service under Unit (see "Before=, After=" in man systemd.unit.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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