diff options
-rwxr-xr-x | lib/RHRD/utils.pm | 42 | ||||
-rwxr-xr-x | test/rml-send | 34 | ||||
-rwxr-xr-x | utils/rhrd-schedules | 22 |
3 files changed, 97 insertions, 1 deletions
diff --git a/lib/RHRD/utils.pm b/lib/RHRD/utils.pm index a4bef22..4ba8a78 100755 --- a/lib/RHRD/utils.pm +++ b/lib/RHRD/utils.pm @@ -89,7 +89,9 @@ use constant { "#575329", "#00FECF", "#B05B6F", "#8CD0FF", "#1E6E00", "#66E1D3", "#CFCDAC", "#A77500", "#6367A9", "#A05837", "#772600", "#D790FF", "#5B4E51", "#8ADBB4", "#83AB58", "#D1F7CE", "#C8D0F6", "#A3A489", "#806C66", "#BF5650", "#66796D", - "#DA007C", "#FF1A59"] + "#DA007C", "#FF1A59"], + + RMLSEND_BINPATH => "/usr/bin/rmlsend" }; sub get_musicpool_color @@ -268,6 +270,44 @@ sub fetch_parse_json } +sub is_rmlsend_installed +{ + return 1 if -x RMLSEND_BINPATH; + return 0; +} + +sub send_rml +{ + my ($rml, $host, $port) = @_; + + my @script = (RMLSEND_BINPATH); + if(defined($host)) { + push(@script, '--to-host=' . $host); + } + if(defined($port)) { + push(@script, '--to-port=' . $port); + } + push(@script, $rml); + + my ($reader, $writer, $error ) = ( new IO::Handle, new IO::Handle, new IO::Handle ); + $writer->autoflush(1); + local $SIG{CHLD} = 'DEFAULT'; + my $pid = open3($writer, $reader, $error, @script); + binmode($reader, ":utf8"); + binmode($writer, ":utf8"); + binmode($error, ":utf8"); + close $writer; + waitpid $pid, 0; + my $err_out = join('', <$error>); + my $read_out = join('', <$reader>); + if ( $? >> 8 ) { + my $log = "\n\nrmlsend: executing RML returned non-zero value\n"; + $log .= "STDERR:\n" . $err_out . "\n" unless $err_out eq ''; + $log .= "STDOUT:\n" . $read_out . "\n" unless $read_out eq ''; + return(1, $log); + } +} + ######################################### ## PV diff --git a/test/rml-send b/test/rml-send new file mode 100755 index 0000000..b5044ac --- /dev/null +++ b/test/rml-send @@ -0,0 +1,34 @@ +#!/usr/bin/perl -w +# +# rhrdlibs +# +# Copyright (C) 2015-2016 Christian Pointner <equinox@helsinki.at> +# +# This file is part of rhrdlibs. +# +# rhrdlibs is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. +# +# rhrdlibs is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with rhrdlibs. If not, see <http://www.gnu.org/licenses/>. +# + +use strict; + +use lib "../lib/"; +use RHRD::utils; + +if(RHRD::utils::is_rmlsend_installed() == 1) { + RHRD::utils::send_rml("RL 3!", "airplay.helsinki.at"); +} else { + print "rmlsend is not installed!\n"; +} + +exit 0 diff --git a/utils/rhrd-schedules b/utils/rhrd-schedules index 2b826e9..4e38872 100755 --- a/utils/rhrd-schedules +++ b/utils/rhrd-schedules @@ -120,6 +120,27 @@ sub generate return $errcnt; } +sub reload_logs +{ + my ($ctx, $year, $month, $day) = @_; + + my @today = Date::Calc::Today(); + if($today[0] == $year && $today[1] == $month && $today[2] == $day) { + if(RHRD::utils::is_rmlsend_installed() == 1) { + print "Reloading today's logs "; + + RHRD::utils::send_rml("RL 3!", "airplay.helsinki.at"); + print "."; + RHRD::utils::send_rml("RL 3!", "airplay2.helsinki.at"); + print "."; + + print " done.\n"; + } else { + print "Log is from today. The playout server need to reload the log but rmlsend is not installed!\n" + } + } +} + sub get { my ($ctx, $year, $month, $day) = @_; @@ -472,6 +493,7 @@ if(defined $ctx) { if($cmd eq "generate") { if($num_args == 2 && $ARGV[1] =~ m/^(\d{4})-(\d{2})-(\d{2})$/) { $ret = generate($ctx, $1, $2, $3); + reload_logs($ctx, $1, $2, $3); } else { print_usage(); $ret = 1; |