Search code examples
raspberry-pisystemd

What could be the difference between automatic and manua startup of systemd service?


I created a simple systemd service on a Raspberry PI(Raspbian GNU/Linux 10) which starts a binary

[Unit]
Description=Bestest description ever

[Service]
User=root
WorkingDirectory=/tmp
ExecStart=/home/pi/Documents/Repos/rpi3b-app/bin/rpi3b_app
Restart=always

[Install]
WantedBy=multi-user.target

When I boot up the PI it starts just fine, but the application behaves weirdly. It's an LED strip controller application written by me and the problematic part is with the GPIO pins. Don't really want to write any more details because I think the problem is related to the systemd service.

If I stop the service manually then start it again everything works perfectly. By stopping and starting again I mean the following commdans:

sudo systemctl stop controller.service

sudo systemctl start controller.service

I really don't understand what's the difference between this and the automatic startup when I boot the system. Hope someone has a good tip where to start the investigation.


Solution

  • It's hard to tell without knowing your binary, but since I encountered similar issues so these are my two cents:

    Your binary may depend on other services that not ready yet when your systemd service starts. You can solve using keyword like after in your service file, so waiting for the other services. The fact that everything works if launch manually makes me think that is a purely timing issue, your service is probabibly launched too early, before other services that may depend on. In may case was the networking service for example.