]> mj.ucw.cz Git - bex.git/blob - lib/perl/BEX/Config.pm
Make editor configurable
[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 # How we run rsync to upload attachments (including options)
60 our $rsync_command = "rsync -a";
61
62 # Which editor should be used for editing jobs
63 our $editor_command = $ENV{"EDITOR"} // "/usr/bin/editor";
64
65 # Various utility functions
66
67 sub parse_machine_list(@);
68
69 sub parse_machine_list(@) {
70         my %set = ();
71         for my $m (@_) {
72                 if ($m eq '*') {
73                         for my $mm (keys %machines) {
74                                 if (ref($machines{$mm}) eq 'HASH') {
75                                         $set{$mm} = 1;
76                                 }
77                         }
78                         next;
79                 }
80                 my $op = 1;
81                 if ($m =~ s{^!}{}) { $op = 0; }
82                 my $v = $machines{$m};
83                 if (!defined $v) {
84                         die "Unknown machine or class: $m\n";
85                 } elsif (ref($v) eq 'HASH') {
86                         $set{$m} = $op;
87                 } elsif (ref($v) eq 'ARRAY') {
88                         for my $mm (parse_machine_list(@$v)) {
89                                 $set{$mm} = $op;
90                         }
91                 }
92         }
93         return sort grep { $set{$_} } keys %set;
94 }
95
96 sub host_name($) {
97         my ($mach) = @_;
98         return $machines{$mach}->{'Host'} // $mach;
99 }
100
101 require $cf_dir . '/config';
102
103 42;