dr-mod / zero-btc-screen

Crypto stock price for RPi Zero
MIT License
310 stars 69 forks source link

Improvement: autostart with boot #2

Closed MayNiklas closed 3 years ago

MayNiklas commented 3 years ago

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

bitcoincoredotbin commented 3 years ago

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.

virtually-ashmai commented 3 years ago

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

Fede068 commented 3 years ago

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

martinatime commented 3 years ago

I added the startup configuration into my PR https://github.com/dr-mod/zero-btc-screen/pull/7

dr-mod commented 3 years ago

Added to README