]> git.ktnx.net Git - mpd-feeder.git/commitdiff
exit cleanly on SIGTERM and SIGINT
authorDamyan Ivanov <dmn@debian.org>
Fri, 12 Nov 2021 07:23:36 +0000 (07:23 +0000)
committerDamyan Ivanov <dmn@debian.org>
Fri, 12 Nov 2021 07:23:36 +0000 (07:23 +0000)
lib/App/MPD/Feeder.pm

index c23b4b465bf6c3c4590b96a549a14000d004d9cc..c495f9c1a257b992c349959157cfe493d4e14dd6 100644 (file)
@@ -58,6 +58,26 @@ use constant DEFAULT_CONFIG_FILE => '/etc/mpd-feeder/mpd-feeder.conf';
 
         $mpd = Net::Async::MPD->new(%conn);
 
 
         $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',
         $mpd->loop->add(
             IO::Async::Signal->new(
                 name       => 'HUP',
@@ -497,6 +517,12 @@ SQL
 
                 exec( "$0", '--config', $self->cfg_file, '--skip-db-update' );
             }
 
                 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;
+            }
         }
     }
 }
         }
     }
 }