]> mj.ucw.cz Git - bex.git/blob - lib/perl/BEX/Config.pm
Configuration files moved from directory "BEX" to "cf"
[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 # Library directory where BEX modules live
19 our $lib = $ENV{"BEX_LIB"} // "lib";
20
21 # Home directory in which everything resides
22 our $home = $ENV{"BEX_HOME"} // ".";
23
24 # Configuration directory
25 our $cf_dir = $home . "/cf";
26
27 # A file whose contents should be prepended before the job. Should start with the "#!" line.
28 our $job_prolog = $cf_dir . '/prolog';
29
30 # A file whose contents should be appended to the job
31 our $job_epilog = $cf_dir . '/epilog';
32
33 # Keep history of successfully completed jobs
34 our $keep_history = 1;
35
36 # Before we try to connect to a host, ping it to check if it's alive
37 our $ping_hosts = 1;
38
39 # Whenever we want to run a job on a machine, we must obtain a lock.
40 # Available locking schemes are:
41 #       none - no locking takes place (dangerous!)
42 #       job - obtain exclusive access to the job, other jobs on the same
43 #             host can run in parallel
44 #       host - obtain exclusive access to the host, other hosts can run
45 #       queue - obtain exclusive access to the whole queue
46 our $locking_scheme = 'host';
47
48 # Maximum number of simultaneously running jobs in `bex prun'
49 our $max_parallel_jobs = 5;
50
51 # When a job fails, skip all other jobs on the same host
52 # (however, when locking_scheme is set to `job', another instance of `bex run'
53 # still could run such jobs in parallel)
54 our $skip_on_fail = 0;
55
56 # How we run ssh (including options)
57 our $ssh_command = "ssh";
58
59 # Various utility functions
60
61 sub parse_machine_list(@);
62
63 sub parse_machine_list(@) {
64         my %set = ();
65         for my $m (@_) {
66                 if ($m eq '*') {
67                         for my $mm (keys %machines) {
68                                 if (ref($machines{$mm}) eq 'HASH') {
69                                         $set{$mm} = 1;
70                                 }
71                         }
72                         next;
73                 }
74                 my $op = 1;
75                 if ($m =~ s{^!}{}) { $op = 0; }
76                 my $v = $machines{$m};
77                 if (!defined $v) {
78                         die "Unknown machine or class: $m\n";
79                 } elsif (ref($v) eq 'HASH') {
80                         $set{$m} = $op;
81                 } elsif (ref($v) eq 'ARRAY') {
82                         for my $mm (parse_machine_list(@$v)) {
83                                 $set{$mm} = $op;
84                         }
85                 }
86         }
87         return sort grep { $set{$_} } keys %set;
88 }
89
90 sub host_name($) {
91         my ($mach) = @_;
92         return $machines{$mach}->{'Host'} // $mach;
93 }
94
95 require $cf_dir . '/config';
96
97 42;