Commit 3072ddc7 authored by Milan's avatar Milan
Browse files

initial commit

parent 25e25357
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
use POSIX;
$|=1;
my $log='/var/log/wunderbox/scheduler-monitor.log';
`touch $log` unless(-e $log);
`chown radioadmin $log`;
open STDOUT, '>>', $log;
open STDERR, '>>', $log;
my $status_file = '/home/radioadmin/radio/scheduler/status/scheduler_status';
my $restart_timeout = 10*60;
my $sleep = 1*60;
my $restart_for_station = {
piradio => 0,
ansage => 0,
colabo => 0,
frapo => 1,
};
my $time=time();
my $c=0;
my $outage_start=undef;
my $url1='';
my $prev_url1='';
while(1==1){
unless(-e $log){
`touch $log`;
`chown radioadmin $log`;
open STDOUT, '>>', $log;
open STDERR, '>>', $log;
}
if($c>0){
# print_info("sleep");
sleep $sleep;
}
$c++;
my $status=do $status_file;
my $current=$status->{current};
my $station_id=$current->{station}->{id};
my $liquidsoap=$status->{liquidsoap};
$prev_url1=$url1;
$url1=$liquidsoap->{station1}->{url}||'';
#skip on empty url
if (defined $url1 eq''){
print_info("could not get status");
$outage_start=undef;
next;
}
#check if url has changed
if ($url1 ne $prev_url1){
print_info("url has changed: '$liquidsoap->{station1}->{url}'");
$outage_start=undef;
next;
}
#no outage or outage ended
unless($liquidsoap->{station1}->{url}=~/^polling/){
if(defined $outage_start){
print_info("outage end: '$liquidsoap->{station1}->{url}'");
}
$outage_start=undef;
next;
}
#outage started
unless(defined $outage_start){
$outage_start=time();
print_info("outage start: '$liquidsoap->{station1}->{url}'");
next;
}
#outage ongoing
print_info("outage for : ".(time()-$outage_start)." seconds on station '$station_id'");
#check if station is marked for restart on error
if ($restart_for_station->{$station_id}ne'1'){
print_info("restart will not be triggered for this station");
next;
}
#restart liquidsoap
if (time()-$outage_start > $restart_timeout){
print_info("restart liquidsoap: '$liquidsoap->{station1}->{url}'");
execute('restart liquidsoap');
$outage_start=undef;
next;
}
}
sub print_info{
my $message=$_[0];
my $time=POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime);
print $time."\t".$message."\n";
}
sub execute{
my $cmd=$_[0];
print_info('EXEC: '.$cmd);
print `$cmd`;
}
This diff is collapsed.
stream-schedule (0.01.0041) trusty; urgency=low
* fix systemd/upstart handling
-- Milan Chrobok <mc@radiopiloten.de> Thu, 16 Nov 2017 23:04:09 +0200
stream-schedule (0.01.0040) trusty; urgency=low
* add station id to alias list
-- Milan Chrobok <mc@radiopiloten.de> Thu, 16 Nov 2017 23:04:09 +0200
stream-schedule (0.01.0039) trusty; urgency=low
* write image temporarily and move, fist stop run level
-- Milan Chrobok <mc@radiopiloten.de> Wed, 15 Nov 2017 23:04:09 +0200
stream-schedule (0.01.0037) trusty; urgency=low
* fix log rotation
-- Milan Chrobok <mc@radiopiloten.de> Fri, 23 Feb 2017 23:04:09 +0200
stream-schedule (0.01.0036) trusty; urgency=low
* add measuring peak and RMS for input and output
-- Milan Chrobok <mc@radiopiloten.de> Fri, 06 Jan 2017 23:04:09 +0200
stream-schedule (0.01.0034) trusty; urgency=low
* adopt log levels
-- Milan Chrobok <mc@radiopiloten.de> Wed, 23 Nov 2016 23:04:09 +0200
stream-schedule (0.01.0033) trusty; urgency=low
* fix saving status, abort on connection loss, decrease sleep if action takes too long
-- Milan Chrobok <mc@radiopiloten.de> Wed, 20 Sun 2016 23:04:09 +0200
stream-schedule (0.01.0030) trusty; urgency=low
* fix logrotate
-- Milan Chrobok <mc@radiopiloten.de> Wed, 20 Sun 2016 23:04:09 +0200
stream-schedule (0.01.0028) trusty; urgency=low
* timeout handling for hanging connections, reset scheduler connection state
-- Milan Chrobok <mc@radiopiloten.de> Wed, 20 Nov 2016 23:04:09 +0200
stream-schedule (0.01.0023) trusty; urgency=low
* reduce log level on broken pipes for gone liquidsoap connections
-- Milan Chrobok <mc@radiopiloten.de> Wed, 25 May 2016 23:04:09 +0200
stream-schedule (0.01.0022) trusty; urgency=low
* retry on hanging sockets, catch broken pipe
-- Milan Chrobok <mc@radiopiloten.de> Tue, 24 May 2016 23:04:09 +0200
stream-schedule (0.01.0021) trusty; urgency=low
* add debug for skipping sync
-- Milan Chrobok <mc@radiopiloten.de> Tue, 24 May 2016 23:04:09 +0200
stream-schedule (0.01.0019) trusty; urgency=low
* fix socket communication
-- Milan Chrobok <mc@radiopiloten.de> Tue, 24 May 2016 22:04:09 +0200
stream-schedule (0.01.0018) trusty; urgency=low
* initial package
-- Milan Chrobok <mc@radiopiloten.de> Sun, 28 Feb 2016 12:04:09 +0200
Source: stream-schedule
Section: sound
Priority: optional
Maintainer: Milan Chrobok <mc@radiopiloten.de>
Build-Depends: debhelper (>= 8)
Build-Depends-Indep: perl
Standards-Version: 3.9.3
Homepage: https://launchpad.net/~mc-1/+archive/stream-schedule
Package: stream-schedule
Architecture: all
Depends: ${misc:Depends},
libconfig-general-perl,
libclone-perl,
libgetopt-long-descriptive-perl,
libtime-hires-perl,
gnuplot-nox,
stream-schedule-liquidsoap,
stream-schedule-gsync
Description: audio stream schedule with with liquidsoap and google calendar
Format-Specification: http://anonscm.debian.org/viewvc/dep/web/deps/dep5.mdwn?view=markup&pathrev=135
Maintainer: Milan Chrobok <mc@radiopiloten.de>
Name: stream-schedule
Files: *
Copyright: 2015 Milan Chrobok <mc@radiopiloten.de>
License: GPL-3+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
.
On Debian systems, the complete text of version 3 of the GNU General
Public License can be found in `/usr/share/common-licenses/GPL-3'.
etc/init/
etc/systemd/system
/etc/stream-schedule/
/etc/logrotate.d/
/usr/share/upstart
/var/log/stream-schedule/
/var/log/stream-schedule/plot
/var/run/stream-schedule/
/usr/share/stream-schedule/status/
\ No newline at end of file
bin/scheduler.pl /usr/bin
bin/scheduler-monitor.pl /usr/bin
etc/init/stream-schedule.conf /etc/init
etc/logrotate.d/stream-schedule /etc/logrotate.d
etc/stream-schedule/stream-schedule.conf /etc/stream-schedule
etc/systemd/system/stream-schedule.service /etc/system.d/system
#! /bin/sh
isUpstart() {
/sbin/init --version 2>/dev/null | grep -q 'upstart' || return 1
echo "upstart" found
return 0
}
isSystemd() {
/bin/systemctl 2>/dev/null | grep -q '\-\.mount' || return 1
echo "systemd found"
return 0
}
if ! getent group audiostream >/dev/null; then
addgroup --system audiostream
fi
if ! getent passwd audiostream >/dev/null; then
adduser --system --ingroup audiostream --home /var/lib/audiostream audiostream
fi
addgroup audiostream pulse
addgroup audiostream pulse-access
addgroup audiostream audio
# user home
if [ -d /var/lib/audiostream/ ]; then
chown audiostream:audiostream /var/lib/audiostream/
chmod 0750 /var/lib/audiostream/
fi
# pid directory
if [ -d /var/run/stream-schedule/ ]; then
chown audiostream:audiostream /var/run/stream-schedule/
chmod 0775 /var/run/stream-schedule/
fi
# status dir
if [ -d /usr/share/stream-schedule/ ]; then
chown audiostream:audiostream /usr/share/stream-schedule/
chmod 0775 /usr/share/stream-schedule/
fi
if [ -d /usr/share/stream-schedule/status/ ]; then
chown audiostream:www-data /usr/share/stream-schedule/status/
chmod 0775 /usr/share/stream-schedule/status/
fi
# log dir
if [ -d /var/log/stream-schedule/ ]; then
chgrp audiostream /var/log/stream-schedule/
chmod 0775 /var/log/stream-schedule/
fi
# plot dir
if [ -d /var/log/stream-schedule/plot/ ]; then
chown -R audiostream:www-data /var/log/stream-schedule/plot/
chmod 0755 /var/log/stream-schedule/plot/
fi
[ -f /etc/stream-schedule/stream-schedule.conf ] && chgrp audiostream /etc/stream-schedule/stream-schedule.conf
[ -f /etc/init/stream-schedule.conf ] && chgrp audiostream /etc/init/stream-schedule.conf
[ -f /etc/logrotate.d/stream-schedule ] && chgrp audiostream /etc/logrotate.d/stream-schedule
[ -f /etc/logrotate.d/stream-schedule ] && chmod 644 /etc/logrotate.d/stream-schedule
if isUpstart; then
echo "stop stream-schedule upstart service"
initctl reload-configuration
status stream-schedule && stop stream-schedule || echo "could not stop service"
start stream-schedule
elif isSystemd; then
echo "stop stream-schedule systemd service"
systemctl enable stream-schedule
systemctl start stream-schedule
fi
exit 0
#! /bin/sh
isUpstart() {
/sbin/init --version 2>/dev/null | grep -q 'upstart' || return 1
echo "upstart" found
return 0
}
isSystemd() {
/bin/systemctl 2>/dev/null | grep -q '\-\.mount' || return 1
echo "systemd found"
return 0
}
if [ "$1" = "purge" ] ; then
if [ -e /etc/stream-schedule/stream-schedule.conf ]; then
rm /etc/stream-schedule/stream-schedule.conf
fi
if [ -e /etc/init/stream-schedule.conf ]; then
rm /etc/init/stream-schedule.conf
fi
fi
exit 0;
#! /bin/sh -e
isUpstart() {
/sbin/init --version 2>/dev/null | grep -q 'upstart' || return 1
echo "upstart" found
return 0
}
isSystemd() {
/bin/systemctl 2>/dev/null | grep -q '\-\.mount' || return 1
echo "systemd found"
return 0
}
if [ "$1" = "remove" ]; then
if isUpstart; then
echo "stop stream-schedule upstart service"
status stream-schedule && stop stream-schedule || echo "could not stop service"
initctl reload-configuration
elif isSystemd; then
echo "stop stream-schedule systemd service"
systemctl stop stream-schedule
systemctl disable stream-schedule
fi
fi
exit 0
#! /bin/sh
isUpstart() {
/sbin/init --version 2>/dev/null | grep -q 'upstart' || return 1
echo "upstart" found
return 0
}
isSystemd() {
/bin/systemctl 2>/dev/null | grep -q '\-\.mount' || return 1
echo "systemd found"
return 0
}
if [ "$1" = "remove" ]; then
if isUpstart; then
echo "stop stream-schedule upstart service"
status stream-schedule && stop stream-schedule || echo "could not stop service"
initctl reload-configuration
elif isSystemd; then
echo "stop stream-schedule service"
systemctl stop stream-schedule
systemctl disable stream-schedule
fi
fi
exit 0
#!/usr/bin/make -f
%:
dh $@
description "stream-schedule"
start on (
net-device-up
and local-filesystems
and runlevel [2345]
)
stop on runlevel [016]
respawn
pre-start script
[ -d /var/run/stream-schedule ] || mkdir /var/run/stream-schedule
chmod 775 /var/run/stream-schedule
chown audiostream /var/run/stream-schedule
[ -f /var/run/stream-schedule/stream-schedule.pid ] && rm /var/run/stream-schedule/stream-schedule.pid
[ -d /var/log/stream-schedule/ ] || mkdir /var/log/stream-schedule/
chmod 755 /var/log/stream-schedule
chown audiostream:www-data /var/log/stream-schedule/
[ -f /var/log/stream-schedule/scheduler.log ] && chmod 664 /var/log/stream-schedule/scheduler.log
[ -f /var/log/stream-schedule/scheduler.log ] && chown audiostream:www-data /var/log/stream-schedule/scheduler.log
true
end script
exec su -s /bin/sh -c 'exec "$0" "$@" 2>>/var/log/stream-schedule/scheduler.log' audiostream -- /usr/bin/scheduler.pl --daemon 2>&1
/var/log/stream-schedule/scheduler.log {
rotate 7
daily
compress
missingok
copytruncate
postrotate
find /var/log/stream-schedule/plot/ -type f -name "monitor-*" -mtime +365 -exec rm {} \;
endscript
# since output will be piped to log, we use copytruncate
# postrotate
# kill -HUP `cat /var/run/stream-schedule/stream-schedule.pid 2>/dev/null` 2>/dev/null || true
# endscript
}
# here all predefined stations are configured
<stations>
<station>
id default
url1 http://localhost:8000/default
title Pause
alias default,none,no
</station>
<station>
id station1
url1 http://host1:8000/station1
url2 http://host2:8000/station1
title this is station one
alias station1,station-1,station-one
</station>
# add more stations here ...
</stations>
<scheduler>
# the schedule file to switch between stations
scheduleFile /usr/share/stream-schedule/status/schedule.csv
# the current status file used for web application
statusFile /usr/share/stream-schedule/status/status
# touch this file to trigger the sync command to update the scheduleFile
triggerSyncFile /usr/share/stream-schedule/status/update
syncCommand streamScheduleSync.pl --from "-1" --till "+7" --output "/usr/share/stream-schedule/status/schedule.csv"
# sleep time in seconds
sleep 30
# offset for switching between stations (in seconds)
switchOffset 8.5
# configuration reload interval in seconds
reload 10
# verbose level for log
verbose 1
# log file
log /var/log/stream-schedule/scheduler.log
# plots with RMS are located here
plotDir /var/log/stream-schedule/plot/
gnuplot /usr/bin/gnuplot
</scheduler>
<liquidsoap>
# UNIX socket file to connect to liquidsoap
#socket /var/run/stream-schedule/liquidsoap.socket
# telnet connection to connect to liquidsoap
host 127.0.0.1
port 1234
</liquidsoap>
[Unit]
Description=audio stream schedule
After=network.target
[Service]
Restart=always
User=audiostream
PIDFile=/var/run/stream-schedule/stream-schedule.pid
ExecStartPre= [ -d /var/run/stream-schedule ] || mkdir /var/run/stream-schedule
ExecStartPre= chmod 775 /var/run/stream-schedule
ExecStartPre= chown audiostream /var/run/stream-schedule
ExecStartPre= [ -f /var/run/stream-schedule/stream-schedule.pid ] && rm /var/run/stream-schedule/stream-schedule.pid
ExecStartPre= [ -d /var/log/stream-schedule/ ] || mkdir /var/log/stream-schedule/
ExecStartPre= chmod 755 /var/log/stream-schedule
ExecStartPre= chown audiostream:www-data /var/log/stream-schedule/
ExecStartPre= [ -f /var/log/stream-schedule/scheduler.log ] && chmod 664 /var/log/stream-schedule/scheduler.log
ExecStartPre= [ -f /var/log/stream-schedule/scheduler.log ] && chown audiostream:www-data /var/log/stream-schedule/scheduler.log
ExecStart=/usr/bin/scheduler.pl --daemon >>/var/log/stream-schedule/scheduler.log 2>&1
ExecReload=/bin/kill -HUP $(cat /var/run/stream-schedule/stream-schedule.pid)
[Install]
WantedBy=multi-user.target
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment