]> mj.ucw.cz Git - bex.git/blob - lib/perl/BEX/Config.pm
The big move -- introduced subcommands
[bex.git] / lib / perl / BEX / Config.pm
1 # Batch EXecutor 3.0 -- Configuration
2 # (c) 2011-2012 Martin Mares <mj@ucw.cz>
3
4 use strict;
5 use warnings;
6
7 package BEX::Config;
8
9 # This file specifies default values, which can be overridden in BEX.cf
10
11 # A hash of all known machines and groups
12 # 'name' => { Option => ... }   for a machine; options:
13 #       Host => 'name'                  Host name to use in ssh, ping, ...
14 # 'name' => ['a','b','c']       for a group containing specified machines/subgroups
15 our %machines = (
16 );
17
18 # Home directory in which everything resides
19 our $bex_home = $ENV{"BEX_HOME"} // ".";
20
21 # Configuration directory
22 our $bex_cf_dir = $bex_home . "/BEX";
23
24 # A file whose contents should be prepended before the job. Should start with the "#!" line.
25 our $job_prolog = $bex_cf_dir . '/prolog';
26
27 # A file whose contents should be appended to the job
28 our $job_epilog = $bex_cf_dir . '/epilog';
29
30 # Keep history of successfully completed jobs
31 our $keep_history = 1;
32
33 # Before we try to connect to a host, ping it to check if it's alive
34 our $ping_hosts = 1;
35
36 # Whenever we want to run a job on a machine, we must obtain a lock.
37 # Available locking schemes are:
38 #       none - no locking takes place (dangerous!)
39 #       job - obtain exclusive access to the job, other jobs on the same
40 #             host can run in parallel
41 #       host - obtain exclusive access to the host, other hosts can run
42 #       queue - obtain exclusive access to the whole queue
43 our $locking_scheme = 'host';
44
45 # Maximum number of simultaneously running jobs in `bprun'
46 our $max_parallel_jobs = 5;
47
48 # When a job fails, skip all other jobs on the same host
49 # (however, when locking_scheme is set to `job', another instance of `brun'
50 # still could run such jobs in parallel)
51 our $skip_on_fail = 0;
52
53 # How we run ssh (including options)
54 our $ssh_command = "ssh";
55
56 # Various utility functions
57
58 sub parse_machine_list(@);
59
60 sub parse_machine_list(@) {
61         my %set = ();
62         for my $m (@_) {
63                 if ($m eq '*') {
64                         for my $mm (keys %machines) {
65                                 if (ref($machines{$mm}) eq 'HASH') {
66                                         $set{$mm} = 1;
67                                 }
68                         }
69                         next;
70                 }
71                 my $op = 1;
72                 if ($m =~ s{^!}{}) { $op = 0; }
73                 my $v = $machines{$m};
74                 if (!defined $v) {
75                         die "Unknown machine or class: $m\n";
76                 } elsif (ref($v) eq 'HASH') {
77                         $set{$m} = $op;
78                 } elsif (ref($v) eq 'ARRAY') {
79                         for my $mm (parse_machine_list(@$v)) {
80                                 $set{$mm} = $op;
81                         }
82                 }
83         }
84         return sort grep { $set{$_} } keys %set;
85 }
86
87 sub host_name($) {
88         my ($mach) = @_;
89         return $machines{$mach}->{'Host'} // $mach;
90 }
91
92 require $bex_cf_dir . '/config';
93
94 42;