]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
no bug - move cereal to its own script
authorDylan William Hardison <dylan@hardison.net>
Sat, 10 Mar 2018 16:10:25 +0000 (11:10 -0500)
committerGitHub <noreply@github.com>
Sat, 10 Mar 2018 16:10:25 +0000 (11:10 -0500)
Bugzilla/DaemonControl.pm
scripts/cereal.pl [new file with mode: 0755]

index 05aaf8130cacc40c3b3face8a06d8acbaf3c79b6..b7f7bcbe97966793d384d30b8bae3237374d0efe 100644 (file)
@@ -39,6 +39,8 @@ our %EXPORT_TAGS = (
     utils => [qw(catch_signal on_exception on_finish)],
 );
 
+use constant CEREAL_BIN    => realpath(catfile( bz_locations->{cgi_path}, 'scripts', 'cereal.pl'));
+
 use constant HTTPD_BIN     => '/usr/sbin/httpd';
 use constant HTTPD_CONFIG  => realpath(catfile( bz_locations->{confdir}, 'httpd.conf' ));
 
@@ -67,41 +69,11 @@ sub catch_signal {
     return $signal_f;
 }
 
-sub cereal {
-    local $PROGRAM_NAME = "cereal";
-    $ENV{LOGGING_PORT} //= 5880;
-
-    my $loop = IO::Async::Loop->new;
-    my $on_stream = sub {
-        my ($stream) = @_;
-        my $protocol = IO::Async::Protocol::LineStream->new(
-            transport    => $stream,
-            on_read_line => sub {
-                my ( $self, $line ) = @_;
-                say $line;
-            },
-        );
-        $loop->add($protocol);
-    };
-    my @signals = (
-        catch_signal('TERM', 0),
-        catch_signal('INT', 0 ),
-        catch_signal('KILL', 0 ),
-    );
-    $loop->listen(
-        host      => '127.0.0.1',
-        service   => $ENV{LOGGING_PORT},
-        socktype  => 'stream',
-        on_stream => $on_stream,
-    )->get;
-    exit Future->wait_any(@signals)->get;
-}
-
 sub run_cereal {
     my $loop   = IO::Async::Loop->new;
     my $exit_f = $loop->new_future;
     my $cereal = IO::Async::Process->new(
-        code         => \&cereal,
+        command      => [CEREAL_BIN],
         on_finish    => on_finish($exit_f),
         on_exception => on_exception( "cereal", $exit_f ),
     );
diff --git a/scripts/cereal.pl b/scripts/cereal.pl
new file mode 100755 (executable)
index 0000000..d5b5564
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/perl
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+use 5.10.1;
+use strict;
+use warnings;
+
+use File::Basename;
+use File::Spec;
+BEGIN {
+    require lib;
+    my $dir = File::Spec->rel2abs(File::Spec->catdir(dirname(__FILE__), '..'));
+    lib->import($dir, File::Spec->catdir($dir, 'lib'), File::Spec->catdir($dir, qw(local lib perl5)));
+}
+
+use Bugzilla::DaemonControl qw(catch_signal);
+use Future;
+use IO::Async::Loop;
+use IO::Async::Protocol::LineStream;
+
+$ENV{LOGGING_PORT} //= 5880;
+
+my $loop = IO::Async::Loop->new;
+my $on_stream = sub {
+    my ($stream) = @_;
+    my $protocol = IO::Async::Protocol::LineStream->new(
+        transport    => $stream,
+        on_read_line => sub {
+            my ( $self, $line ) = @_;
+            say $line;
+        },
+    );
+    $loop->add($protocol);
+};
+my @signals = qw( TERM INT KILL );
+
+$loop->listen(
+    host      => '127.0.0.1',
+    service   => $ENV{LOGGING_PORT},
+    socktype  => 'stream',
+    on_stream => $on_stream,
+)->get;
+
+exit Future->wait_any(map { catch_signal($_, 0) } @signals)->get;
\ No newline at end of file