diff --git a/tools_hive/utils/beekeeper.pl b/tools_hive/utils/beekeeper.pl index 5a7b44799..c7eca6a8d 100644 --- a/tools_hive/utils/beekeeper.pl +++ b/tools_hive/utils/beekeeper.pl @@ -27,11 +27,6 @@ $config = eval(uri_unescape($config)); die "Could not parse command line arguments:\n$@" if $@; -# save pid to pid file as provided -open(PID, ">$config->{'pid_file'}") or die "Couldn't open $config->{'pid_file'} file: $!"; -print PID $$; -close PID; - # require SiteDefs and LoadPlugins require $config->{'include_script'}; @@ -48,10 +43,22 @@ @INC = grep -d && !$seen{$_} && ($seen{$_} = 1), (reverse(@SiteDefs::ENSEMBL_LIB_DIRS), map("$_/modules", grep /tools/, @{$SiteDefs::ENSEMBL_PLUGINS}), @{$SiteDefs::ENSEMBL_EXTRA_INC}, @INC); $ENV{'PERL5LIB'} = join ':', @INC; -# Finally, run the script with correct paths. This is done with 'do', not 'system' so it's run as a part -# of the same process. We have already saved it's pid in the pid file which can be used to kill the process. -# It also maintains INCs, but that's not of much use, unfortunately (see above). -@ARGV = @{$config->{'command_args'}}; -do $config->{'script'}; +# Fork the process +my $pid = fork(); + +if (defined $pid) { + if ($pid == 0) { + # Child process + exec($config->{'script'}, @{$config->{'command_args'}}) or die "Couldn't exec: $!"; + } else { + # Parent process + # Save the child's PID to pid file using the provided name + open(PID, ">$config->{'pid_file'}") or die "Couldn't open $config->{'pid_file'} file: $!"; + print PID $pid; + close PID; + } +} else { + die "Fork failed: $!"; +} # DONE diff --git a/tools_hive/utils/beekeeper_manager.pl b/tools_hive/utils/beekeeper_manager.pl index 4dfbc9d31..58c462548 100644 --- a/tools_hive/utils/beekeeper_manager.pl +++ b/tools_hive/utils/beekeeper_manager.pl @@ -37,16 +37,24 @@ use Cwd qw(abs_path); use URI::Escape qw(uri_escape); use Time::localtime; +use Getopt::Long; + +# Configure GetOpt to not panic if it sees options that haven't been explicitly declared +Getopt::Long::Configure("pass_through"); $Bin =~ s|\.snapshot?/[^/]+|latest|; #replacing snapshot in path to latest my $path = $Bin; + my $no_cache = grep { $_ eq '--no_cache_config' } @ARGV; my $redirect_out = grep { $_ eq '--redirect_output' } @ARGV; my $kill = grep { $_ eq '--kill' } @ARGV; -my $sleep_time = grep({ $_ =~ /^\-\-sleep/ } @ARGV) ? undef : "0.5"; +my $keep_alive = grep { $_ eq '--keep_alive' } @ARGV; my $include_script = abs_path("$Bin/../../../ensembl-webcode/conf/includeSiteDefs.pl"); my $command_args = []; +my $sleep_time = 0.5; # default sleep time +GetOptions("sleep=f" => \$sleep_time); + for (@ARGV) { $path = $_ and last if !$path; if ($_ =~ /^\-\-path=?(.*)/) { @@ -117,8 +125,8 @@ # --sleep arg push @$command_args, '--sleep', $sleep_time if $sleep_time; -# any other args in the command line -push @$command_args, grep($_ !~ /^\-\-(redirect_output|no_cache_config|kill|path)$/, @ARGV); +# keep beekeeper running +push @$command_args, '--loop_until', 'FOREVER' if $keep_alive; # wrapper command my $command = sprintf q(perl %s/beekeeper.pl '%s' %s), $Bin, uri_escape(Data::Dumper->new([{