Re: Running VDR from systemd on Raspberry Pi OS

Marko Mäkelä <[email protected]> Tue, 27 Dec 2022 22:49:17 +0200
Newsgroups gmane.linux.vdr
Message-ID <Y6taTdcxaZ50edIT@jyty>
Tue, Dec 27, 2022 at 12:04:00PM +0200, Marko Mäkelä wrote:
>I might configure some more, such as:
>
>* Write some udev rule so that when the USB storage is unplugged and 
>replugged, the file system will be auto-mounted and VDR service will 
>be started.
>* Restore /etc/systemd/logind.conf to HandlePowerKey=poweroff so that 
>the system can be easily shut down by pressing the Power button again.

I finally figured it out mostly. What is missing is a nice way of 
overriding the power button. When VDR is running, the button should be 
handled by VDR; otherwise, pressing the power button should trigger 
system shutdown, like it does by default.

First, I removed the custom /etc/fstab entry. Everything will be 
controlled by systemd as follows:

sudo mkdir -m 000 /video
sudo tee /etc/systemd/system/video.mount << "EOF"
[Unit]
BindsTo=dev-disk-by\x2dlabel-VDR.device
After=dev-disk-by\x2dlabel-VDR.device
Requires=systemd-fsck@dev-disk-by\x2dlabel-VDR.service
After=systemd-fsck@dev-disk-by\x2dlabel-VDR.service
[Mount]
Where=/video
What=/dev/disk/by-label/VDR
Type=ext4
Options=defaults,noatime,nofail
[Install]
WantedBy=dev-disk-by\x2dlabel-VDR.device
EOF
sudo tee /etc/systemd/system/vdr.service << "EOF"
[Unit]
Description=Runs VDR when storage is plugged in
After=systemd-user-sessions.service plymouth-quit-wait.service
After=rc-local.service
[email protected]
BindsTo=dev-disk-by\x2dlabel-VDR.device
After=dev-disk-by\x2dlabel-VDR.device
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]
WantedBy=dev-disk-by\x2dlabel-VDR.device
EOF
sudo systemctl enable video.mount
sudo systemctl enable vdr
sudo udevadm control --reload
cat > /var/lib/vdr/vdr-shutdown.sh << "EOF"
#!/bin/sh
set -eu
if [ "$5" = 1 ]
then
   sudo udisksctl unmount -b /dev/disk/by-label/VDR
   sudo udisksctl power-off -b /dev/disk/by-label/VDR
   PK=/etc/systemd/logind.conf.d/00-powerkey.conf
   sudo mv -f "$PK".disabled "$PK" || :
   sudo systemctl restart systemd-logind
   sudo mv -f "$PK" "$PK".disabled
   sudo systemctl stop vdr
fi
EOF
chmod +x /var/lib/vdr/vdr-shutdown.sh
sudo mkdir /etc/systemd/logind.conf.d
sudo tee /etc/systemd/login.conf.d/00-powerkey.conf.disabled << "EOF"
[Login]
HandlePowerKey=poweroff
EOF
sudo systemctl restart systemd-logind

In addition to these, /etc/systemd/login.conf needs to be edited so that 
its [Login] section says HandlePowerKey=ignore.

I also had a udev rule that would execute "systemctl restart 
systemd-logind" when the storage is plugged in. Without that, if I 
plugged in the storage (and got VDR auto-started), then pressed the 
power button, and then repeated the same (unplug, replug, press the 
power button again), the system would shut down abruptly.

If there is a better way to make systemd-logind ignore the power button 
as long as VDR is running, please let me know. I tried adding 
Conflicts=exit.target to the vdr.service, but that did not prevent the 
shutdown. A rule Conflicts=shutdown.target means that the service shall 
be terminated on shutdown, according to "man 7 systemd.special".

	Marko

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