From 8c909531538857b39cbf61ec7d5f20e252af175a Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Sat, 10 Jan 2015 16:38:27 +1300 Subject: [PATCH] Switch to using a script to update the MOTD --- ChangeLog | 4 ++++ bin/mythtv-status | 2 +- bin/mythtv-update-motd | 37 +++++++++++++++++++++++++++++++-- debian/changelog | 6 ++++++ debian/cron.d | 2 +- debian/init.d | 32 ++++------------------------- debian/install | 1 + man/mythtv-update-motd.1 | 44 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 96 insertions(+), 32 deletions(-) create mode 100644 man/mythtv-update-motd.1 diff --git a/ChangeLog b/ChangeLog index 6a1af3f..4b2b509 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-01-10 Andrew Ruthven + Make the cron.d file for Debian use mythtv-update-motd to stop + systemd from being upset. + 2014-12-02 Andrew Ruthven Add in more UTF-8 encodings as required for Perl v5.18, thanks to Jan Schneider for reporting the UTF-8 issue. diff --git a/bin/mythtv-status b/bin/mythtv-status index 6c099b9..83cf6cc 100755 --- a/bin/mythtv-status +++ b/bin/mythtv-status @@ -85,7 +85,7 @@ my @size_thresholds = ( my $return_code_only = 0; -my $VERSION = '0.10.6'; +my $VERSION = '0.10.7'; # Some display blocks are disabled by default: $c->{'display'}{'Shows due to Auto Expire'} = 0; diff --git a/bin/mythtv-update-motd b/bin/mythtv-update-motd index b7e080b..3d5703b 100755 --- a/bin/mythtv-update-motd +++ b/bin/mythtv-update-motd @@ -1,5 +1,11 @@ #!/bin/bash +# Run mythtv-status to update the MOTD. + +NAME=mythtv-update-motd +WORKFILE=/var/run/motd +TEMPFILE=/var/run/motd.mythtv-status + . /etc/default/mythtv-status if [ x$RUN != xyes ] @@ -7,11 +13,38 @@ then exit fi +# Debian Wheezy+ handles the MOTD differently. +[ -f /var/run/motd.dynamic ] && WORKFILE=/var/run/motd.dynamic + +# Just incase someone has removed their motd file. +[ -f $WORKFILE ] || touch $WORKFILE +[ -f /var/run/motd.orig ] || cp $WORKFILE /var/run/motd.orig + +# If the tempfile is less than 15 minutes old, object, otherwise +# we'll assume that something went wrong and remove it. +if [ -f $TEMPFILE ]; then + AGE=$(stat -c "%Z" $TEMPFILE); + if (( $AGE > $(date +'%s') - 900 )) + then + echo "I think another $NAME is running." + exit 1 + fi +fi + [ ! -f /var/run/motd.orig ] && cp /var/run/motd /var/run/motd.orig cp /var/run/motd.orig /var/run/motd.new ret=0 -mythtv-status $ARGS -h $HOST >> /var/run/motd.new 2> /dev/null || ret=$? +mythtv-status $ARGS -h $HOST >> $TEMPFILE 2> /dev/null || ret=$? if [ $ret -eq 0 -o $ret -eq 1 ]; then - [ -f /var/run/motd.new ] && mv /var/run/motd.new /var/run/motd + if [ ! -f $TEMPFILE ]; then + echo My temporary file has gone away, failed. + exit 1 + else + mv $TEMPFILE $WORKFILE + fi +else + # Something else went wrong, remove the temp file. + rm $TEMPFILE + exit 1 fi diff --git a/debian/changelog b/debian/changelog index 8c475b9..3b8b7f9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +mythtv-status (0.10.7-1) unstable; urgency=low + + * New upstream release (Closes: #772801). + + -- Andrew Ruthven Sat, 10 Jan 2015 15:56:21 +1300 + mythtv-status (0.10.6-1) unstable; urgency=low * New upstream release. diff --git a/debian/cron.d b/debian/cron.d index 2efa2eb..0dcad6a 100644 --- a/debian/cron.d +++ b/debian/cron.d @@ -1,4 +1,4 @@ # # Regular cron jobs for the mythtv-status package # -*/10 * * * * root [ -x /etc/init.d/mythtv-status ] && /etc/init.d/mythtv-status reload > /dev/null +*/10 * * * * root [ -x /usr/sbin/mythtv-update-motd ] && /usr/sbin/mythtv-update-motd > /dev/null diff --git a/debian/init.d b/debian/init.d index e64f719..5111a17 100644 --- a/debian/init.d +++ b/debian/init.d @@ -63,37 +63,13 @@ case "$1" in start|reload|refresh|restart|force-reload) log_daemon_msg "Updating $DESC" "$NAME" - # Just incase someone has removed their motd file. - [ -f $WORKFILE ] || touch $WORKFILE - [ -f /var/run/motd.orig ] || cp $WORKFILE /var/run/motd.orig - - # If the tempfile is less than 15 minutes old, object, otherwise - # we'll assume that something went wrong and remove it. - if [ -f $TEMPFILE ]; then - AGE=$(stat -c "%Z" $TEMPFILE); - if expr $AGE \> $(date +'%s') - 900 - then - log_warning_msg "I think another $NAME is running." + if ! /usr/sbin/mythtv-update-motd; then + log_failure_msg "Failed to update MOTD" exit 1 - fi - fi - - cp /var/run/motd.orig $TEMPFILE - ret=0 - start=$(date) - $DAEMON $ARGS -h $HOST >> $TEMPFILE || ret=$? - if [ $ret -eq 0 -o $ret -eq 1 ]; then - if [ ! -f $TEMPFILE ]; then - log_failure_msg "My temporary file has gone away, failed." - exit 1 - else - mv $TEMPFILE $WORKFILE - fi - log_end_msg 0 - else - log_failure_msg fi + + log_end_msg 0 ;; stop) log_daemon_msg "Stopping $DESC" "$NAME" diff --git a/debian/install b/debian/install index 8cb8553..850b6ef 100644 --- a/debian/install +++ b/debian/install @@ -1,5 +1,6 @@ bin/mythtv-status usr/bin bin/mythtv_recording_now usr/bin bin/mythtv_recording_soon usr/bin +bin/mythtv-update-motd /usr/sbin molly-guard/40-mythtv-recording-soon etc/molly-guard/run.d debian/lintian/overrides/mythtv-status usr/share/lintian/overrides diff --git a/man/mythtv-update-motd.1 b/man/mythtv-update-motd.1 new file mode 100644 index 0000000..d0d88b6 --- /dev/null +++ b/man/mythtv-update-motd.1 @@ -0,0 +1,44 @@ +.\" Hey, EMACS: -*- nroff -*- +.\" First parameter, NAME, should be all caps +.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection +.\" other parameters are allowed: see man(7), man(1) +.TH MYTHTV-UPDATE-MOTD 1 "2015-01-11" +.\" Please adjust this date whenever revising the manpage. +.\" +.\" Some roff macros, for reference: +.\" .nh disable hyphenation +.\" .hy enable hyphenation +.\" .ad l left justify +.\" .ad b justify to both left and right margins +.\" .nf disable filling +.\" .fi enable filling +.\" .br insert line break +.\" .sp insert n+1 empty lines +.\" for manpage-specific macros, see man(7) +.SH NAME +mythtv-update-motd \- update the MOTD with the MythTV backend status +.SH SYNOPSIS +.B mythtv-update-motd +.SH DESCRIPTION +.B mythtv-update-motd +Update the system MOTD with the status of the MythTV backend. +It checks the host which is configured in +.I /etc/default/mythtv-status +with the HOST setting. +.SH OPTIONS +None +.SH "EXIT STATUS" +.TP +.B 0 +Updated MOTD with MythTV status +.TP +.B 1 +Failed to update MOTD with MythTV status +.SH FILES +.B /etc/default/mythtv-status +Config file +.SH SEE ALSO +.BR mythtv-status (1), +.SH AUTHOR +mythtv-update-motd and this manpage were written by Andrew Ruthven +. -- 2.30.2