Clean reboot?

Having issues with your DietPi installation, or, found a bug? Post it here.
Post Reply
pakikje
Posts: 102
Joined: Fri Nov 11, 2016 2:04 pm

Clean reboot?

Post by pakikje » Sun Aug 18, 2019 9:32 pm

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:
-smb
-nfs
-syncthing
-Homeassistant
-Lighttpd

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

The script:

Code: Select all

#!/bin/bash

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' http://192.168.0.32/cgi-bin/video.cgi?msubmenu=jpg
wget -O /home/homeassistant/.homeassistant/www/voordeur.jpg  --http-user=xxx --http-password='yyy' http://192.168.0.72/axis-cgi/jpg/image.cgi
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

FILE=/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
fi
FILE=/home/homeassistant/.homeassistant/www/keuken.jpg
if test -f "$FILE"; then
    echo "$FILE exist"
  else  echo "keuken.jpg missing $(date)" >> /root/error.log && sudo reboot
fi

User avatar
MichaIng
Legend
Posts: 1638
Joined: Sat Nov 18, 2017 5:21 pm

Re: Clean reboot?

Post by MichaIng » Mon Aug 19, 2019 6:34 pm

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.

pakikje
Posts: 102
Joined: Fri Nov 11, 2016 2:04 pm

Re: Clean reboot?

Post by pakikje » Mon Aug 19, 2019 9:14 pm

very usefull info! Thnx man.

Post Reply