From: Tomas Doran Date: Fri, 6 Nov 2009 00:53:03 +0000 (+0000) Subject: Implement auto restart when the app is updated X-Git-Tag: 0.000000_01~85^2~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=dd3c4caf431e743a02f5e720fee1c4e7a91dd8db;p=catagits%2FGitalist.git Implement auto restart when the app is updated --- diff --git a/lib/Gitalist.pm b/lib/Gitalist.pm index 8b0cee5..0def39d 100644 --- a/lib/Gitalist.pm +++ b/lib/Gitalist.pm @@ -20,8 +20,34 @@ __PACKAGE__->config( name => 'Gitalist', default_view => 'Default', default_model => 'Git', # Yes, we are going to be changing this. + # Set to 1 to make your fcgi die the request after you push :) + exit_at_end_of_request_if_updated => 0, ); +{ + my $version; + my $get_version = sub { + my $gitdir = shift->path_to('.git'); + my $version = qx{cat "$gitdir/`cut -d' ' -f2 .git/HEAD`"}; + chomp $version; + return $version; + }; + + after setup_finalize => sub { + my $c = shift; + $version = $c->$get_version + if $c->config->{exit_at_end_of_request_if_updated}; + }; + after handle_request => sub { + my $c = shift; + if ($version) { + my $new = $c->$get_version; + exit 0 unless $new eq $version; + } + }; +} + + # Start the application __PACKAGE__->setup();