当tvheadend录制/ KDE会话处于活动状态时,防止关闭

当tvheadend(或vdr)当前正在录制时,我正在寻找一种防止关机/待机的方法。

到目前为止我发现了什么:

  • 在rsnapshot运行时防止关闭 :我不喜欢它,因为它要求tvheadend具有root权限,并且引用的链接似乎提供了不再起作用的变体。

  • TVHeadend Wakup :设置唤醒时间工作正常。 但是pm-suspend不检查KDE会话是否处于活动状态但是立即暂停。

  • 如何关机不需要管理员密码? :仅适用于非常特殊的情况:检查用户是否已登录

我看到两个解决方案:

  • TVHeadend脚本调​​用某些KDE函数来询问KDE状态(屏幕锁定,用户登录等)并发出关闭/暂停调用,如上例所示。
  • 或者修改KDE的关闭行为,以便检查当前是否有任何TVH录像处于活动状态。

我找不到关于这两种变体的任何文档。

找到一个非常简单的解决方
创建一个文件/etc/pm/sleep.d/70-check-recordings

在此文件中检查当前录制是否处于活动状态。 如果是,请返回exit 1 。 而已。 暂停将被中止。

我的脚本看起来像这样,它基于这个在tvheadend 。

 $ cat /etc/pm/sleep.d/00-check-recordings #!/bin/bash # # this script sets ACPI Wakeup alarm and stops standby if a recording is active # safe_margin - minutes to start up system before the earliest timer # bootup system x sec. before timer safe_margin=60 # modify if different location for tvheadend dvr/log path cd ~hts/.hts/tvheadend/dvr/log ###################### start_date=0 stop_date=0 current_date=`date +%s` for i in $( ls ); do tmp_start=`cat $i | grep '"start":' | cut -f 2 -d " " | cut -f 1 -d ","` tmp_stop=`cat $i | grep '"stop":' | cut -f 2 -d " " | cut -f 1 -d ","` # logger "$0: $i from $(date -d @$tmp_start) to $(date -d @$tmp_stop)" start_extra=`cat $i | grep '"start_extra":' | cut -f 2 -d " " | cut -f 1 -d ","` stop_extra=`cat $i | grep '"stop_extra":' | cut -f 2 -d " " | cut -f 1 -d ","` let tmp_start=$tmp_start-$start_extra*60 let tmp_stop=$tmp_stop+$stop_extra*60 # logger "$0: $i from $(date -d @$tmp_start) to $(date -d @$tmp_stop)" # if recording is active, immediately stop suspend # tmp_stop > now and tmp_start < now if [ $((tmp_stop)) -gt $((current_date)) -a $((tmp_start)) -lt $((current_date)) ]; then name=`grep -h -A 1 title $i | grep -v title | sed 's/.*: "\(.*\)"$/\1/'` logger "$0: Currently RECORDING $name. No Suspend until $(date -d @$tmp_stop!)" exit 1; fi # only check future recordings # tmp_stop > now and tmp_start > now if [ $((tmp_stop)) -gt $((current_date)) -a $((tmp_start)) -gt $((current_date)) ]; then # take lower value (tmp_start or start_date) # (start_date = 0) or (tmp_start < start_date) if [ $((start_date)) -eq 0 -o $((tmp_start)) -lt $((start_date)) ]; then start_date=$tmp_start stop_date=$tmp_stop name=`grep -h -A 1 title $i | grep -v title | sed 's/.*: "\(.*\)"$/\1/'` fi fi done wake_date=$((start_date-safe_margin)) # set up wakeup alarm if [ $((start_date)) -ne 0 ]; then logger "$0: Set Wakealarm for $name to $(date -d @$wake_date)" echo 0 > /sys/class/rtc/rtc0/wakealarm echo $wake_date > /sys/class/rtc/rtc0/wakealarm fi 

现在设置KDE以在超时后处理待机状态。 如果录制处于活动状态,则上述脚本将中止KDE备用。

请参阅MythTV文档中的内容 。

使用咖啡因 。 它是一种应用程序,可防止电源管理操作在某些应用程序运行时触发。 然后,您可以进入system settings – > power management并将应用程序添加到列表中。

我写了一个脚本来关闭和唤醒基于Tvheadend活动的系统。 当Tvheadend处于活动状态时,它不会挂起您的系统。 你可以在GitHub上找到它。