From: Damyan Ivanov Date: Fri, 12 Nov 2021 07:23:36 +0000 (+0000) Subject: exit cleanly on SIGTERM and SIGINT X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=99ee7dfadcf8b6c86a2da8f1f33b552efa22c4c1;hp=7f5a01ffe5b4c4feb09aea13fe7cddc6c89a4ab2;p=mpd-feeder.git exit cleanly on SIGTERM and SIGINT --- diff --git a/lib/App/MPD/Feeder.pm b/lib/App/MPD/Feeder.pm index c23b4b4..c495f9c 100644 --- a/lib/App/MPD/Feeder.pm +++ b/lib/App/MPD/Feeder.pm @@ -58,6 +58,26 @@ use constant DEFAULT_CONFIG_FILE => '/etc/mpd-feeder/mpd-feeder.conf'; $mpd = Net::Async::MPD->new(%conn); + $mpd->loop->add( + IO::Async::Signal->new( + name => 'TERM', + on_receipt => sub { + $log->debug("SIGTERM received. Stopping loop"); + $mpd->loop->stop('quit'); + }, + ) + ); + + $mpd->loop->add( + IO::Async::Signal->new( + name => 'INT', + on_receipt => sub { + $log->debug("SIGINT received. Stopping loop"); + $mpd->loop->stop('quit'); + }, + ) + ); + $mpd->loop->add( IO::Async::Signal->new( name => 'HUP', @@ -497,6 +517,12 @@ SQL exec( "$0", '--config', $self->cfg_file, '--skip-db-update' ); } + + if ( 'quit' eq $result ) { + $log->trace("quitting because of 'quit' loop result"); + $self->stop; + exit 0; + } } } }