Skip to content

Commit

Permalink
Update beekeeper scripts for the hive 2.2 -> 2.7 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
azangru committed Nov 14, 2024
1 parent 333e0fd commit 8a8ad10
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
28 changes: 18 additions & 10 deletions tools_hive/utils/beekeeper.pl
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,10 @@

# get passed config hash
my ($config) = @ARGV;
print uri_unescape($config), "\n";
$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'};

Expand All @@ -48,10 +44,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
14 changes: 11 additions & 3 deletions tools_hive/utils/beekeeper_manager.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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=?(.*)/) {
Expand Down Expand Up @@ -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([{
Expand Down

0 comments on commit 8a8ad10

Please sign in to comment.