dr-mod/zero-btc-screen

Improvement: autostart with boot

MayNiklas opened this issue · 5 comments

Hey @dr-mod ,
I've noticed something and thought of a better way solving autostart:

Following the README, I wasn't able to get the skript to autostart.

In /etc/rc.local you are using /usr/bin/python3 /home/pi/zero-btc-screen/main.py&.
-> it won't work, because the skript is being executed from the wrong directory (e.g. the font is missing).

There are 3 ways we could easily solve this:

  1. Installing the missing font system wide
  2. Instead of executing the python skript directly, we could run a "start.sh" which would first cd into the right folder (we also could use ´crontab's @reboot' instead of using rc.local
  3. Creating a systemd service

I personally think, that systmd would be the cleanest way to solve this: we would have a autorestart in case something would go wrong and we also would receive logs!

Implementing this would be really simple:

sudo nano /etc/systemd/system/btc-screen.service

Then we would insert the following content:

[Unit]
Description=zero-btc-screen
After=network.target

[Service]
ExecStart=/usr/bin/python3 -u main.py
WorkingDirectory=/home/pi/zero-btc-screen
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi

[Install]
WantedBy=multi-user.target

To start & enable our newly created service:

sudo systemctl start btc-screen.service
sudo systemctl enable btc-screen.service

In case you think this would be a great idea, I would love to add it to the README.md.
But before I do so: is this even wanted? We also could provide a sample .service file, the user could easily copy into the right folder without manually creating it.

King regards,
Niki

Option 3 worked like a charm.

Just tried to set it up using the Readme and it did not work. Thankfully you posted this here!

+1 would move to main Read me for future users.

I was having this same issue, and creating the systemd service worked like a charm. Thanks.

I had the same issue but with the systemd run perfect. Thank you @MayNiklas !

I added the startup configuration into my PR #7

Added to README