Clean reboot?

Hello you all,

I wrote a bash-script that will check if a webcam is still “up” and if it isn’t it will reboot the SBC. (script checks for a snapshot.jpg from the webcam) I noticed however that:

“reboot -f” doesn’t work (“reboot” does)
Sometimes “reboot” doesn’t work properly (when i ssh into the SBC afterwards, most dietpi-services are not active anymore) (failed startup?)

What is the proper way to reboot? How do i script (bash) “dietpi-services stop”?

ps: (some more info) i have 2 webcam (usb) connected to the SBC. Lots of times 1 of these webcams will “shutdown” or remain “open” so a proces that wants to take a snapshot from that cam will not work.I fear that it is a linux-“driver” problem.

services that i have running:

I used to take snapshots with “motion”. Right now i use fswebcam for that.

The script:


rm /home/homeassistant/.homeassistant/www/woonkamer.jpg
rm /home/homeassistant/.homeassistant/www/keuken.jpg
rm /home/homeassistant/.homeassistant/www/tuin.jpg
rm /home/homeassistant/.homeassistant/www/voordeur.jpg

wget -O /home/homeassistant/.homeassistant/www/tuin.jpg --http-user=xxx --http-password=yyy'
wget -O /home/homeassistant/.homeassistant/www/voordeur.jpg  --http-user=xxx --http-password='yyy'
fswebcam -d /dev/video0 -r 640x480 -F 10 /home/homeassistant/.homeassistant/www/keuken.jpg
fswebcam -d /dev/video1 -r 600x800 --rotate 90 -F 10 /home/homeassistant/.homeassistant/www/woonkamer.jpg

if test -f "$FILE"; then
    echo "$FILE exist"
  else echo "woonkamer.jpg missing $(date)" >> /root/error.log && sudo reboot
if test -f "$FILE"; then
    echo "$FILE exist"
  else  echo "keuken.jpg missing $(date)" >> /root/error.log && sudo reboot

reboot is the command that should be called. Not sure what reboot -f does, but since it does not call shutdown, regular shutdown tasks, like service stops might be missing, which is dangerous and can lead to data loss.

If on boot not all services are running, then indeed you can check the boot script and service states, e.g.
systemctl status dietpi-boot
dietpi-services status

When booting the system with screen attached, you should as well see dietpi-services starting services before the login prompt appears.

journalctl allows to check further details about start and order of systemd units, or if some failed.

Inside scripts, the dietpi-* command aliases are not available, so call the scripts with full path there:
/DietPi/dietpi/dietpi-services stop

To check why the webcams fail by times, you might want to check dmesg or journalctl for errors. Probably a voltage related issue, e.g. if you have some external drive attached as well and during peak times the overall shared 1.2A are reached.

very usefull info! Thnx man.