Skip to content

Instantly share code, notes, and snippets.

/log_rotate.diff Secret

Created February 12, 2015 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/234d8c714885e6d7b77a to your computer and use it in GitHub Desktop.
Save anonymous/234d8c714885e6d7b77a to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojo/Log.pm b/lib/Mojo/Log.pm
index 63d50d5..846b9bd 100644
--- a/lib/Mojo/Log.pm
+++ b/lib/Mojo/Log.pm
@@ -56,6 +56,8 @@ sub new {
return $self;
}
+sub reopen { delete shift->{handle} }
+
sub warn { shift->log(warn => @_) }
sub _format {
diff --git a/lib/Mojo/Server/Prefork.pm b/lib/Mojo/Server/Prefork.pm
index d3f39a6..73b34e3 100644
--- a/lib/Mojo/Server/Prefork.pm
+++ b/lib/Mojo/Server/Prefork.pm
@@ -93,6 +93,10 @@ sub run {
($w->{graceful} = steady_time) and last unless $w->{graceful};
}
};
+ local $SIG{USR1} = sub {
+ $self->app->log->reopen;
+ kill 'USR1', $_ for keys %{$self->{pool}};
+ };
# Preload application before starting workers
$self->start->app->log->info("Manager $$ started");
@@ -191,6 +195,7 @@ sub _spawn {
# Clean worker environment
$SIG{$_} = 'DEFAULT' for qw(CHLD INT TERM TTIN TTOU);
$SIG{QUIT} = sub { $loop->max_connections(0) };
+ $SIG{USR1} = sub { $self->app->log->reopen };
delete @$self{qw(poll reader)};
srand;
diff --git a/lib/Mojolicious/Plugin/Mount.pm b/lib/Mojolicious/Plugin/Mount.pm
index 5a78acd..1d4ef6a 100644
--- a/lib/Mojolicious/Plugin/Mount.pm
+++ b/lib/Mojolicious/Plugin/Mount.pm
@@ -7,7 +7,7 @@ sub register {
my ($self, $app, $conf) = @_;
my $path = (keys %$conf)[0];
- my $embed = Mojo::Server->new->load_app($conf->{$path});
+ my $embed = Mojo::Server->new->load_app($conf->{$path})->log($app->log);
# Extract host
my $host;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment