Commit 557fbef3 authored by Milan's avatar Milan
Browse files

make systemd stop work again, add pid to logs, add log on stop

parent 33b1e7b8
#!/bin/sh
#pkill -9 -f "/usr/bin/scheduler.pl"
[ -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
......@@ -17,7 +17,7 @@ use IO::Socket::UNIX qw(SOCK_STREAM);
use IO::Socket::INET qw(SOCK_STREAM);
use IO::Select;
#$| = 1;
$| = 1;
our $verbose = undef;
updateTime();
......@@ -64,17 +64,33 @@ our $isVerboseEnabled2 = ( defined $verbose ) && ( $verbose >= 2 );
our $isVerboseEnabled3 = ( defined $verbose ) && ( $verbose >= 3 );
our $isVerboseEnabled4 = ( defined $verbose ) && ( $verbose >= 4 );
$SIG{INT} = sub {
info("received INT signal, cleanup and quit") if $isVerboseEnabled0;
closeSocket($fileSocket);
closeSocket($telnetSocket);
exit;
};
$SIG{TERM} = sub {
info("connection lost to liquidsoap (terminated), close sockets") if $isVerboseEnabled3;
info("received TERM signal, cleanup and quit") if $isVerboseEnabled0;
closeSocket($fileSocket);
closeSocket($telnetSocket);
exit;
};
$SIG{HUP} = sub {
info("received HUP signal, reload configuration (toBeDone, workaround=quit") if $isVerboseEnabled0;
closeSocket($fileSocket);
closeSocket($telnetSocket);
exit;
};
$SIG{PIPE} = sub {
info("connection lost to liquidsoap (broken pipe), close sockets") if $isVerboseEnabled3;
info("connection lost to liquidsoap (broken pipe), close sockets") if $isVerboseEnabled0;
closeSocket($fileSocket);
closeSocket($telnetSocket);
};
our $log = $config->{scheduler}->{log};
daemonize($log) if defined $params->{daemon};
......@@ -1225,7 +1241,8 @@ sub info {
my $caller = getCaller();
my $date = timeToDatetime();
my $line = "$date\tINFO";
my $pid = $$;
my $line = "$date\t$pid\tINFO";
$line .= sprintf( "\t%-16s", $caller ) if defined $caller;
$message =~ s/\n/\\n/g;
$message =~ s/\r/\\r/g;
......@@ -1239,9 +1256,10 @@ sub warning {
my $now = time();
my $date = timeToDatetime($now);
my $pid = $$;
$message =~ s/\n/\\n/g;
$message =~ s/\r/\\r/g;
print "$date\tWARN\t$message\n";
print "$date\t$pid\tWARN\t$message\n";
$status->{warnings}->{$message} = $now unless defined $onlyToFile;
}
......@@ -1250,7 +1268,8 @@ sub error {
my $now = time();
my $date = timeToDatetime($now);
print "$date\tERROR\t$message\n";
my $pid = $$;
print "$date\t$pid\tERROR\t$message\n";
$status->{warnings}->{$message} = $now;
}
......@@ -1260,7 +1279,8 @@ sub exitOnError {
my $now = time();
my $date = timeToDatetime($now);
print STDERR "$date\tERROR\t$caller\t$message\n";
my $pid = $$;
print STDERR "$date\t$pid\tERROR\t$caller\t$message\n";
$status->{warnings}->{$message} = $now;
exit;
}
......
#!/bin/sh
while true
do
pkill -f "/usr/bin/scheduler.pl"
[ -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
su -s /bin/sh -c 'exec "$0" "$@" >> /var/log/stream-schedule/scheduler.log 2>&1' audiostream -- /usr/bin/scheduler.pl --daemon
sleep 3
done
stream-schedule (0.01.0051) xenial; urgency=low
stream-schedule (0.01.0054) xenial; urgency=low
* fix systemd service again
-- Milan Chrobok <mc@radiopiloten.de> Thu, 27 Apr 2018 16:54:09 +0200
stream-schedule (0.01.0053) xenial; urgency=low
* fix systemd service location
-- Milan Chrobok <mc@radiopiloten.de> Thu, 21 Apr 2018 16:54:09 +0200
......
......@@ -15,6 +15,4 @@ Depends: ${misc:Depends},
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
......@@ -4,4 +4,4 @@ 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/systemd/system
bin/start-stream-schedule.sh
bin/prepare-stream-schedule.sh
......@@ -4,13 +4,16 @@ Description=audio stream schedule
After=network.target
[Service]
Type=simple
Restart=on-failure
RestartSec=3
#Type=simple
Restart=always
RestartSec=1s
User=audiostream
Group=audiostream
ExecStart=/bin/start-stream-schedule.sh
ExecReload=/bin/kill -HUP $(cat /var/run/stream-schedule/stream-schedule.pid)
ExecStartPre=+/bin/prepare-stream-schedule.sh >>/var/log/stream-schedule/scheduler.log 2>&1
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) >>/var/log/stream-schedule/scheduler.log 2>&1
[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