]> mj.ucw.cz Git - bex.git/commitdiff
Creation of queues must be explicit
authorMartin Mares <mj@ucw.cz>
Wed, 15 Feb 2012 22:39:46 +0000 (23:39 +0100)
committerMartin Mares <mj@ucw.cz>
Wed, 15 Feb 2012 22:39:46 +0000 (23:39 +0100)
bex
lib/bin/queue [new file with mode: 0755]
lib/perl/BEX/Queue.pm

diff --git a/bex b/bex
index 237db3f84d2c9b23a0312eb39ad8c71ff061c107..860dce98c9747021c119f904961c3a5935658276 100755 (executable)
--- a/bex
+++ b/bex
@@ -27,6 +27,7 @@ job           Operations on queued jobs
 ls (l)         Show queues and jobs on them
 mach           List known machines and groups
 prun (pr)      Parallel version of `run'
+queue          Operations on queues
 run (r)                Run queued jobs
 AMEN
                        exit 0;
diff --git a/lib/bin/queue b/lib/bin/queue
new file mode 100755 (executable)
index 0000000..2fb46fa
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/perl
+# Batch EXecutor 3.0 -- Operations on Queues
+# (c) 2011-2012 Martin Mares <mj@ucw.cz>
+
+use strict;
+use warnings;
+use Getopt::Long;
+use BEX;
+
+my $init;
+
+GetOptions(
+       "init!" => \$init,
+) && @ARGV == 1 or die <<AMEN ;
+Usage: bex queue [<options>] <queue>
+
+Options:
+--init                 Create a new queue
+AMEN
+
+my $queue_name = shift @ARGV;
+
+if ($init) {
+       my $path = $BEX::Config::home . '/' . $queue_name;
+       -d $path and die "Queue directory $path already exists\n";
+       mkdir $path;
+       mkdir "$path/hosts";
+       mkdir "$path/jobs";
+       print "Queue $queue_name initialized.\n";
+} else {
+       my $queue = BEX::Queue->new($queue_name);
+       print "Queue $queue is OK\n";
+}
index b7165098cf4171cbd6ee2d4a5726c08884eaad9a..36a19c5060f250c7a1031888e5230ab19490cd8c 100644 (file)
@@ -16,10 +16,8 @@ sub new($;$) {
        my ($class, $name) = @_;
        $name //= 'queue';
        my $path = $BEX::Config::home . '/' . $name;
-       -d $path or die "Queue directory $path does not exist\n";
-       for my $d ("hosts", "jobs") {
-               -d "$path/$d" or mkdir "$path/$d" or die "Cannot create directory $path/$d: $!";
-       }
+       -d $path or die "Queue directory $path does not exist (use bex queue --init to create it)\n";
+       -d "$path/hosts" && -d "$path/jobs" or die "Queue directory $path is misconfigured\n";
        my $queue = {
                'Name' => $name,
                'Path' => $path,
@@ -235,7 +233,7 @@ sub unlock($) {
        delete $queue->{'LockName'};
 }
 
-# Unsafe (does not check fcntl, only existence of a lock file), but should be enough for bq
+# Unsafe (does not check fcntl, only existence of a lock file), but should be enough for `bex ls'
 sub is_locked($$$) {
        my ($queue, $machine, $jid) = @_;
        given ($BEX::Config::locking_scheme) {