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