Run Glances at RBPI startup
If you’re reading this on fediverse and the layout is off, here’s the link to the original blog post with a nice text & pictures layout.
In my previous post, I struggled to run glances on my Raspberry Pi Zero W. After a first reboot I stared to my Home Assistant dashboard and wondered where is the data from my RaspberryPi. Of course, I ran it manually from the shell, it didn’t restart by itself.
If you ask me to tell you out of my head how to make a service/script start after a reboot, I will stare you blank.
After a bit of googling, I found out there are at least 4 different ways to do it.
Firstly, I tried to make glances to start using crontab method:
sudo crontab -e
#then I added the following command to crontab:
@reboot sh /<path to my glances>/glances -w
It failed, don’t know why, maybe because Raspbian doesn’t like @restart command.
Second try – rc.local:
I tinkered a bit with rc.local but I gave up quickly.
Third try – systemd – it worked!
1. Go to systemd directory
cd /etc/systemd/system
2. create a definition file for the service
sudo nano glances_w.service
3. Add the following text to glances_w.service file:
[Install]
WantedBy=multi-user.target
[Unit]
Description=Glances Web Server
Wants=network-online.target
After=network-online.target
[Service]
User=tomi
Group=adm
ExecStart=/home/tomi/glances/bin/glances -w
ExecStartPre=/bin/sleep 10
Type=simple
[Timer]
OnStartupSec=25
Change parameter User (tomi) to your user and ExecStart (/home/tomi/glances/bin/glances -w) with path to your glances start command.
4. Enable and start service
sudo systemctl enable glances_w.service
sudo systemctl start glances_w.service
5. Check the status of the service
systemctl status glances_w.service
It should give you something like:
Thanks to this forum post – now my glances start autmatically after a reboot. Of course it didn’t go smoothly as described above. I had to tinker with the User and Group parameter. I didn’t know which user should I insert. Then I didn’t know the name of the group.
So I had to find it out using:
groups
groups tomi
The bottom line is: without forums and manuals for linux commands, I’d be completely disabled when using linux. I’m using it on and off for 30 years, but still struggling with basic commands. I wonder if I will ever climb above my current level: google-the-command-copy-paste-modify-repeat
Leave a Reply