Sun, Dec 25, 2022 at 01:10:51PM +0100, Udo Richter wrote:
On 24.12.22 10:33, Marko Mäkelä wrote:
then
sudo service vdr stop
sudo umount /video
sudo udisksctl power-off -b /dev/sda
fi
The first step appears to terminate the shell script, because the shell
is a subprocess of VDR. So, the storage will remain mounted and powered
on. I guess that we need to launch a separate "vdr-shutdown" service
that would take care of the remaining steps. Has someone already
implemented something like this?
Maybe you can prevent that by backgrounding and setting some bash trap's
on SIGINT or SIGKILL.
All these steps depend on each other: VDR must be stopped before the
video directory can be unmounted, and actually any pending writes should
be durably submitted before the device is powered off. That would make
any asynchronous invocation a little more challenging.
I did not test it carefully yet, but I understood from the systemd
documentation that the following might work as intended (umount as soon
as all file handles are closed by VDR):
sudo systemd-umount /video
sudo service vdr stop
I just learned about "man systemd.mount" via this question on automating
backups to USB storage: https://unix.stackexchange.com/questions/89881/
However, I'd say the most clean way is to include the unmount and
udiskctrl into the vdr shutdown itself, so these commands run within
the vdr service after the vdr process stops. That way you just have to
fire the service stop and are done.
Do you mean implementing that as part of VDR plugin?
Or if you want to go full systemd, you can probably do a service that
does the mount/unmount/poweroff on start/stop, and then add that as
requirement to the vdr service.
A simple change to the shutdown script would be to have it execute
something like "sudo shutdown -h now" (or whatever invocation systemd
prefers). That will umount and power off the USB storage just fine.
I think that I might actually go down that route, because currently the
Raspberry Pi runs no other services than VDR. Except for the -s script,
the vdr.service file that I posted yesterday already works for me.
I did not find any systemd integration with udisksctl, other than as
part of an implicit poweroff service.
I could also avoid defining a shutdown script at all, and instead define
a command script for invoking shutdown. That could be invoked when there
are no timed recordings coming up for a while. I would have to remember
to power up the system manually for the next timed recording. This would
allow the power button on the remote control to be mapped to a "suspend"
function that would make VDR stop the video output and stop polling the
tuner. The USB SSD could remain powered on; I do not think it will
consume much power when not being accessed.
Marko
_______________________________________________
vdr mailing list
vdr@xxxxxxxxxxx
https://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr