#!/usr/bin/perl

use strict;
use warnings;
use English qw/-no_match_vars OUTPUT_AUTOFLUSH EXECUTABLE_NAME/;
$OUTPUT_AUTOFLUSH = 1;

use lib qw(libs);
use API::Config;
BEGIN { use lib $API::Config::Config->{'Website_libs'} }
use ECS::Config;
use FindBin ();
use File::Spec::Functions;

use API::GP::Daemon;

my $daemon = API::GP::Daemon->new();
$SIG{HUP} = sub {
	$daemon->restart(1);
};
$SIG{TERM} = sub {
	$daemon->shutdown(1);
};
$daemon->run();
if ( $daemon->restart ) {
	# reload SELF
	my $script = File::Basename::basename( $0 );
	my $SELF = catfile( $FindBin::Bin, $script );
	exec $EXECUTABLE_NAME, $SELF, @ARGV; 
}

exit;

