Running VDR from systemd on Raspberry Pi OS

Marko Mäkelä <[email protected]> Sat, 24 Dec 2022 11:33:19 +0200
Newsgroups gmane.linux.vdr
Message-ID <Y6bHXxmgQzUfBktE@jyty>
Yesterday, I finally bought external storage for my Raspberry Pi based 
VDR setup, a Samsung Portable SSD T7. It supports USB 3, but it also 
works on the Raspberry Pi 2's USB 2.0 and does not consume too much 
power. My old tower PC case based system that I had set up in 2004 has 
now been replaced with something that is better in every thinkable 
respect: power consumption, noise (passive cooling, no HDDs), speed, and 
size (not much larger than the remote control unit).

Hardware:
* Raspberry Pi 2
* Pi TV hat
* TV hat case
* an IR receiver attached via soldered wires to the TV hat, at GPIO pin 18
* a remote control unit (from an old Hauppauge Nova-T PCI card)
* Samsung Portable SSD T7 (1 TB)

Software:
* Raspberry OS Legacy installed on a MicroSD card, with no GUI
* sudo apt install ir-keytable
* VDR 2.6.3 (or 2.6.2) compiled from source
* https://github.com/reufer/rpihddevice/ compiled from source
* "make install" to /usr/local

My /boot/config.txt includes the following lines:
dtoverlay=gpio-ir,gpio_pin=18
dtparam=audio=on
gpu_mem=256

In /etc/rc_maps.cfg (the configuration file of ir-keytable), ensure that 
there is a line like the following that will match the remote control 
unit that you are using:
* * hauppauge.toml
The above works for several RC5 based Hauppauge remote control units.

To prevent the Power button on the remote control unit from shutting 
down the entire system, add the following to the [Login] section of 
/etc/systemd/logind.conf:

HandlePowerKey=ignore

The default is HandlePowerKey=poweroff.

Use mkfs.ext4 to replace the FAT file system of the only partition of 
the T7. There is no need to change the partitioning or specify a block 
size or alignment, because the physical block size is reported as 512 
bytes. Optionally, you may set a label by executing something like this: 
tune2fs -L VDR /dev/sda1

You may create a mount point:

sudo mkdir -m 000 /video

Then, add a line like this to /etc/fstab to have the storage mounted 
automatically:

LABEL=VDR /video ext4 defaults,noatime,nofail 0 1

You may replace the LABEL=VDR with whatever symbolic link you have in 
/dev/disk/by-label (see also tune2fs above). On my system, I actually 
wrote PARTUUID=33d32895-01 because there is a symbolic link 
/dev/disk/by-partuuid/33d32895-01 that identifies the partition.

Once the storage is mounted, execute the following:
sudo mkdir /video/video
sudo chown pi:pi /video/video

The next step is to configure VDR to start up correctly. I have some 
configuration files in /var/lib/vdr. For testing, I used to start VDR 
manually from the command line, and shut it down by choosing "restart" 
from the OSD menu. Now I want it to restart automatically, but only if 
suitable USB storage has been plugged in:

sudo tee /etc/systemd/system/vdr.service << EOF
[Unit]
After=systemd-user-sessions.service plymouth-quit-wait.service
After=rc-local.service
[email protected]
After=video.mount
[email protected]

ConditionPathExists=/video/video

[Service]
User=pi
ExecStart=/usr/local/bin/vdr --no-kbd --lirc=/dev/lirc0 -Prpihddevice -v /video/video -s /var/lib/vdr/vdr-shutdown.sh
TimeoutStartSec=infinity
Type=idle
Restart=on-failure
RestartSec=1s
TTYVTDisallocate=yes

[Install]
Alias=display-manager.service
EOF

This will replace the getty process on virtual terminal 1 (tty1). If the 
storage is not plugged within 90 seconds from startup (I do not know how 
to configure that timeout), then an error message will appear on the 
console. No getty will be started on tty1 in any case; you can always 
log in from tty2 by pressing Alt+F2.

The shutdown script /var/lib/vdr/vdr-shutdown.sh does not work as 
intended yet:

#!/bin/sh

if [ "$5" = 1 ]
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?

After the "umount" and "udisksctl" commands are executed, it is safe to 
unplug the storage. The LED of the SSD will shortly change color and 
then turn off during the execution of the "udisksctl" command.

What I am also missing is a udev rule that would automatically mount the 
storage and attempt to start up VDR as soon as the storage is plugged 
in. Currently, I have to manually execute the following if I plug in the 
drive to an already running system:

sudo mount /video
sudo service vdr start

This configuration provides a rather simple user interface for VDR. No 
keyboard or mouse is needed, just the remote control unit, a display, 
and optionally the USB cable, if the system has other uses that are 
independent of VDR.

For timed recordings, I think that on the Raspberry Pi, it is easiest to 
let the VDR process run all the time. Starting up the Pi based on timer 
would require additional hardware.

One thing that I'd like to improve in that regard is to let VDR shut 
down all tuners when the system is idle. This could be based on an 
inactivity timer or an explicit user action, such as pressing a button 
on the remote control. The video output would shut off, and the tuner 
would be powered off, except when needed for something (EPG scan, 
recording). As soon as a button is pressed on the remote control unit, 
the user interface would spring back to life.

Happy holidays,

	Marko

_______________________________________________
vdr mailing list
[email protected]
https://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr