coren has uploaded a new change for review.
https://gerrit.wikimedia.org/r/64575
Change subject: Tool Labs: Allow jsub to parse script qsub opts
......................................................................
Tool Labs: Allow jsub to parse script qsub opts
Change-Id: I22ba2aaf0b0b7d1cea1585508594c5c51ba74fe3
---
M packages/jobutils/usr/local/bin/jsub
1 file changed, 68 insertions(+), 29 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/labs/toollabs
refs/changes/75/64575/1
diff --git a/packages/jobutils/usr/local/bin/jsub
b/packages/jobutils/usr/local/bin/jsub
index 2d5b47d..08f2cb8 100755
--- a/packages/jobutils/usr/local/bin/jsub
+++ b/packages/jobutils/usr/local/bin/jsub
@@ -6,6 +6,7 @@
'-a' => 1, '-b' => 1, '-cwd' => 0, '-e' => 1, '-hard' => 0, '-i' => 1,
'-j' => 1,
'-l' => 1, '-now' => 1, '-N' => 1, '-o' => 1, '-p' => 1, '-q' => 1,
'-soft' => 0,
'-sync' => 1, '-v' => 1, '-wd' => 1,
+ '-mem' => 1, '-once' => 0, '-stderr' => 0, '-continuous' => 0,
);
my %qsargs;
my @args;
@@ -19,34 +20,18 @@
$continuous = 1 if $script eq 'jstart';
+my @options;
while($#ARGV > 0) {
- if(defined $qsubargs{$ARGV[0]}) {
- $arg = shift;
- $qsargs{$arg} = $qsubargs{$arg}? $ARGV[0]: '';
- if($arg eq '-N' or $arg eq '-q') {
- shift if $qsubargs{$arg};
- next;
- }
- push @args, $arg;
- push @args, shift if $qsubargs{$arg};
- } elsif ($ARGV[0] eq '-mem') {
- shift;
- $memory = shift;
- die "$script: memory value must be an integer followed by 'k', 'm' or
'g'\n" unless $memory =~ m/^([1-9][0-9]*[mMgGkK])$/;
- } elsif ($ARGV[0] eq '-once') {
- $once = 1;
- shift;
- } elsif ($ARGV[0] eq '-stderr') {
- $stderr = 1;
- shift;
- } elsif ($ARGV[0] eq '-continuous') {
- $continuous = 1;
- $once = 1;
- shift;
- } else {
- last;
+ last unless defined $qsubargs{$ARGV[0]};
+ my $opt = shift;
+ my $optarg = undef;
+ if($qsubargs{$opt}) {
+ die "$script: option $opt requires an argument\n" unless $#ARGV > 0;
+ $optarg = shift;
}
+ push @options, [ $opt, $optarg ];
}
+
if($#ARGV<0 or $ARGV[0] =~ m/^-/) {
print STDERR <<"END"
@@ -78,10 +63,63 @@
my $exe = shift;
my $prog = `/usr/bin/which $exe`;
chomp $prog;
-$prog = readlink $prog while -l $prog;
-my $cwd = `pwd`;
-chomp $cwd;
-$prog = "$cwd/$exe" unless -f $prog and -x $prog;
+while(-l $prog) {
+ my $symlink = readlink $prog;
+ if($symlink =~ m{^/}) {
+ $prog = $symlink;
+ next;
+ }
+ $prog =~ s{/[^/]+$}{};
+ while($symlink =~ m{^\.\./(.*)}) {
+ $symlink = $1;
+ $prog =~ s{/[^/]+$}{};
+ }
+ $prog .= "/$symlink";
+}
+
+print "prog?: $prog\n";
+unless($prog =~ m{^/}) {
+ my $cwd = `pwd`;
+ chomp $cwd;
+ $prog = "$cwd/$exe";
+ $prog =~ s{/\./}{/}g;
+}
+
+open EXE, "<$prog" or die "$prog: $!\n";
+my $shebang;
+while(read EXE, $shebang, 2) {
+ last unless $shebang =~ m/^#[!\$]/;
+ my $rest =<EXE>;
+ next if $shebang eq '#!';
+ next unless $rest =~ m/\s* ( -\S+ ) (?: \s+ ( [^# \n\t]+ ) )?/x;
+ unshift @options, [ $1, $2 ];
+}
+close EXE;
+
+
+foreach my $option (@options) {
+ my($opt, $optval) = @$option;
+ if($opt eq '-mem') {
+ $memory = $optval;
+ die "$script: memory value must be an integer followed by 'k', 'm' or
'g'\n" unless $memory =~ m/^([1-9][0-9]*[mMgGkK])$/;
+ } elsif($opt eq '-once') {
+ $once = 1;
+ } elsif($opt eq '-stderr') {
+ $stderr = 1;
+ } elsif($opt eq '-continuous') {
+ $continuous = 1;
+ $once = 1;
+ } else {
+ if($opt eq '-l') {
+ $memory = $1 if $optval =~ s/h_vmem=([0-9]+[mMgGkK]),?//;
+ next if $optval =~ m/^,?$/;
+ }
+ $qsargs{$opt} = $optval;
+ next if $opt eq '-N' or $opt eq '-q' or $opt eq '-b';
+ push @args, $opt;
+ push @args, $optval if defined $optval;
+ }
+}
my $jobname = 'unknown';
$jobname = $1 if $prog =~ m{([^/.]+)(\.[^/]*)?$};
@@ -113,6 +151,7 @@
if($continuous) {
push @args, '-q', 'continuous';
+ push @args, '-b', $sqargs{'-b'} if defined $qsargs{'-b'};
open QSUB, '|-', '/usr/bin/qsub', @args or die "\[$now\] unable to start
qsub: $!\n";
print QSUB "#!/bin/bash\n";
print QSUB "while ! " . shell_quote($prog, @ARGV) . "; do\n";
--
To view, visit https://gerrit.wikimedia.org/r/64575
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I22ba2aaf0b0b7d1cea1585508594c5c51ba74fe3
Gerrit-PatchSet: 1
Gerrit-Project: labs/toollabs
Gerrit-Branch: master
Gerrit-Owner: coren <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits