29
use Sbuild::Sysconfig;
32
33
our (@ISA, @EXPORT);
35
@ISA = qw(Exporter Sbuild::ConfBase);
36
@EXPORT = qw($HOME $arch $max_build $nice_level $idle_sleep_time
37
$min_free_space @take_from_dists @no_auto_build
38
$no_build_regex $build_regex @weak_no_auto_build
39
$delay_after_give_back $pkg_log_keep $pkg_log_keep
40
$build_log_keep $daemon_log_rotate $daemon_log_send
41
$daemon_log_keep $warning_age $error_mail_window
42
$statistics_period $sshcmd $wanna_build_user
43
$no_warn_pattern $should_build_msgs apt_get sudo
44
$autoclean_interval $secondary_daemon_threshold
45
$admin_mail $statistics_mail $dupload_to
46
$dupload_to_non_us $dupload_to_security
47
$log_queued_messages $wanna_build_dbbase read);
37
@EXPORT = qw($reread_config);
52
sub convert_sshcmd ();
55
40
my $reread_config = 0;
57
# Originally from the main namespace.
58
(our $HOME = $ENV{'HOME'})
59
or die "HOME not defined in environment!\n";
60
# Configuration files.
61
my $config_global = "/etc/buildd.conf";
62
my $config_user = "$HOME/.builddrc";
63
my $config_global_time = 0;
64
my $config_user_time = 0;
67
chomp( our $arch = `dpkg --print-architecture 2>/dev/null` );
70
our $idle_sleep_time = 5*60;
71
our $min_free_space = 50*1024;
72
our @take_from_dists = qw();
73
our @no_auto_build = ();
74
our $no_build_regex = "^(contrib/|non-free/)?non-US/";
75
our $build_regex = "";
76
our @weak_no_auto_build = ();
77
our $delay_after_give_back = 8 * 60; # 8 hours
78
our $pkg_log_keep = 7;
79
our $build_log_keep = 2;
80
our $daemon_log_rotate = 1;
81
our $daemon_log_send = 1;
82
our $daemon_log_keep = 7;
84
our $error_mail_window = 8*60*60;
85
our $statistics_period = 7;
88
our $wanna_build_user = $Buildd::username;
89
our $no_warn_pattern = '^build/(SKIP|REDO|SBUILD-GIVEN-BACK|buildd\.pid|[^/]*.ssh|chroot-[^/]*)$';
90
our $should_build_msgs = 1;
91
our $apt_get = "/usr/bin/apt-get";
92
our $sudo = "/usr/bin/sudo";
93
our $autoclean_interval = 86400;
94
our $secondary_daemon_threshold = 70;
95
our $admin_mail = "USER-porters";
96
our $statistics_mail = 'USER-porters';
97
our $dupload_to = "anonymous-ftp-master";
98
our $dupload_to_non_us = "anonymous-non-us";
99
our $dupload_to_security = "security";
100
our $log_queued_messages = 0;
101
our $wanna_build_dbbase = "$arch/build-db";
103
sub ST_MTIME () { 9 }
105
sub read_file ($\$) {
106
my $filename = shift;
107
my $time_var = shift;
109
my @stat = stat( $filename );
110
$$time_var = $stat[ST_MTIME];
111
delete $INC{$filename};
118
read_file( $config_global, $config_global_time );
119
read_file( $config_user, $config_user_time );
123
sub convert_sshcmd () {
125
if ($sshcmd =~ /-l\s*(\S+)\s+(\S+)/) {
126
($main::sshuser, $main::sshhost) = ($1, $2);
128
elsif ($sshcmd =~ /(\S+)\@(\S+)/) {
129
($main::sshuser, $main::sshhost) = ($1, $2);
132
$sshcmd =~ /(\S+)\s*$/;
133
($main::sshuser, $main::sshhost) = ("", $1);
136
$sshcmd .= " -S $sshsocket";
142
Buildd::Conf::read();
145
$SIG{'USR1'} = sub ($) { $reread_config = 1; };
147
sub check_reread_config () {
148
my @stat_user = stat( $config_user );
149
my @stat_global = stat( $config_global );
151
if ( $reread_config ||
152
(@stat_user && $config_user_time != $stat_user[ST_MTIME]) ||
153
(@stat_global && $config_global_time != $stat_global[ST_MTIME])) {
154
logger( "My config file has been updated -- rereading it\n" );
155
Buildd::Conf::read();
42
sub init_allowed_keys {
45
$self->SUPER::init_allowed_keys();
47
my $validate_program = sub {
50
my $key = $entry->{'NAME'};
51
my $program = $self->get($key);
53
die "$key binary is not defined"
54
if !defined($program) || !$program;
56
die "$key binary '$program' does not exist or is not executable"
60
my $validate_directory = sub {
63
my $key = $entry->{'NAME'};
64
my $directory = $self->get($key);
66
die "$key directory is not defined"
67
if !defined($directory) || !$directory;
69
die "$key directory '$directory' does not exist"
73
my $validate_ssh = sub {
77
# TODO: Provide self, config and entry contexts, which functions to
78
# get at needed data. Provide generic configuration functions.
80
$validate_program->($self, $self->{'KEYS'}->{'SSH'});
82
my $ssh = $self->get('SSH');
83
my $sshuser = $self->get('SSH_USER');
84
my $sshhost = $self->get('SSH_HOST');
85
my @sshoptions = @{$self->get('SSH_OPTIONS')};
86
my $sshsocket = $self->get('SSH_SOCKET');
91
push (@command, $ssh);
92
push (@command, '-l', $sshuser) if $sshuser;
93
push (@command, '-S', $sshsocket) if $sshsocket;
94
push (@command, @sshoptions) if @sshoptions;
95
push (@command, $sshhost);
98
$self->set('SSH_CMD', \@command);
101
our $HOME = $self->get('HOME');
102
$main::HOME = $HOME; # TODO: Remove once Buildd.pm uses $conf
103
my $arch = $self->get('ARCH');
110
CHECK => $validate_program,
111
DEFAULT => $Sbuild::Sysconfig::programs{'APT_GET'}
113
'AUTOCLEAN_INTERVAL' => {
116
'BUILD_LOG_KEEP' => {
119
'BUILD_LOG_REGEX' => {
122
'DAEMON_LOG_FILE' => {
123
DEFAULT => "$HOME/daemon.log"
125
'DAEMON_LOG_KEEP' => {
128
'DAEMON_LOG_ROTATE' => {
131
'DAEMON_LOG_SEND' => {
134
'DELAY_AFTER_GIVE_BACK' => {
135
DEFAULT => 8 * 60 # 8 hours
138
DEFAULT => 'anonymous-ftp-master'
140
'DUPLOAD_TO_NON_US' => {
141
DEFAULT => 'anonymous-non-us'
143
'DUPLOAD_TO_SECURITY' => {
144
DEFAULT => 'security'
146
'ERROR_MAIL_WINDOW' => {
149
'IDLE_SLEEP_TIME' => {
152
'LOG_QUEUED_MESSAGES' => {
158
'MIN_FREE_SPACE' => {
170
'NO_BUILD_REGEX' => {
171
DEFAULT => '^(contrib/|non-free/)?non-US/'
176
'NO_WARN_PATTERN' => {
177
DEFAULT => '^build/(SKIP|REDO|SBUILD-GIVEN-BACK|buildd\.pid|[^/]*.ssh|chroot-[^/]*)$'
180
# Set once running as a system service.
181
# DEFAULT => "${Sbuild::Sysconfig::paths{'LOCALSTATEDIR'}/run/buildd.pid"
182
DEFAULT => "$HOME/build/buildd.pid"
187
'SECONDARY_DAEMON_THRESHOLD' => {
190
'SHOULD_BUILD_MSGS' => {
197
DEFAULT => $Sbuild::Sysconfig::programs{'SSH'},
198
CHECK => $validate_ssh,
202
CHECK => $validate_ssh,
206
CHECK => $validate_ssh,
210
CHECK => $validate_ssh,
214
CHECK => $validate_ssh,
216
'STATISTICS_MAIL' => {
219
'STATISTICS_PERIOD' => {
223
CHECK => $validate_program,
224
DEFAULT => $Sbuild::Sysconfig::programs{'SUDO'}
226
'TAKE_FROM_DISTS' => {
229
'WANNA_BUILD_DBBASE' => {
230
DEFAULT => "$arch/build-db"
232
'WANNA_BUILD_USER' => {
233
DEFAULT => $Buildd::username
238
'WEAK_NO_AUTO_BUILD' => {
245
$self->set_allowed_keys(\%buildd_keys);
251
my $HOME = $self->get('HOME');
253
# Variables are undefined, so config will default to DEFAULT if unset.
254
my $admin_mail = undef;
257
my $autoclean_interval = undef;
258
my $build_log_keep = undef;
259
my $build_regex = undef; # Should this be user settable?
260
my $daemon_log_file = undef;
261
my $daemon_log_keep = undef;
262
my $daemon_log_rotate = undef;
263
my $daemon_log_send = undef;
264
my $delay_after_give_back = undef;
265
my $dupload_to = undef;
266
my $dupload_to_non_us = undef;
267
my $dupload_to_security = undef;
268
my $error_mail_window = undef;
269
my $idle_sleep_time = undef;
270
my $log_queued_messages = undef;
271
my $max_build = undef;
272
my $min_free_space = undef;
273
my $nice_level = undef;
275
my $no_build_regex = undef;
276
my $no_detach = undef;
277
my $no_warn_pattern = undef;
279
my $pkg_log_keep = undef;
280
my $secondary_daemon_threshold = undef;
281
my $should_build_msgs = undef;
283
my $ssh_user = undef;
284
my $ssh_host = undef;
286
my $ssh_socket = undef;
287
my $statistics_mail = undef;
288
my $statistics_period = undef;
291
my $wanna_build_dbbase = undef;
292
my $wanna_build_user = undef;
293
my $warning_age = undef;
294
my @weak_no_auto_build;
296
my $global = $Sbuild::Sysconfig::paths{'BUILDD_CONF'};
297
my $user = "$HOME/.builddrc";
298
my %config_time = ();
303
sub ST_MTIME () { 9 }
305
my @config_files = ($global, $user);
307
$reread = 1 if $reread_config;
309
foreach (@config_files) {
311
$config_time{$_} = 0;
313
if (!defined($self->get('CONFIG_TIME')->{$_}) ||
314
$self->get('CONFIG_TIME')->{$_} < $stat[ST_MTIME]) {
315
$config_time{$_} = $stat[ST_MTIME];
321
# Need to reread all config files, even if one is updated.
323
foreach (@config_files) {
325
my $e = eval `cat "$_"`;
327
print STDERR "E: $_: Errors found in configuration file:\n$@";
330
$self->get('CONFIG_TIME')->{$_} = $config_time{$_};
335
# Set configuration if updated.
337
$self->set('ADMIN_MAIL', $admin_mail);
338
$self->set('APT_GET', $apt_get);
339
$self->set('ARCH', $arch);
340
$self->set('AUTOCLEAN_INTERVAL', $autoclean_interval);
341
$self->set('BUILD_LOG_KEEP', $build_log_keep);
342
$self->set('BUILD_REGEX', $build_regex);
343
$self->set('DAEMON_LOG_FILE', $daemon_log_file);
344
$self->set('DAEMON_LOG_KEEP', $daemon_log_keep);
345
$self->set('DAEMON_LOG_ROTATE', $daemon_log_rotate);
346
$self->set('DAEMON_LOG_SEND', $daemon_log_send);
347
$self->set('DELAY_AFTER_GIVE_BACK', $delay_after_give_back);
348
$self->set('DUPLOAD_TO', $dupload_to);
349
$self->set('DUPLOAD_TO_NON_US', $dupload_to_non_us);
350
$self->set('DUPLOAD_TO_SECURITY', $dupload_to_security);
351
$self->set('ERROR_MAIL_WINDOW', $error_mail_window);
352
$self->set('IDLE_SLEEP_TIME', $idle_sleep_time);
353
$self->set('LOG_QUEUED_MESSAGES', $log_queued_messages);
354
$self->set('MAX_BUILD', $max_build);
355
$self->set('MIN_FREE_SPACE', $min_free_space);
356
$self->set('NICE_LEVEL', $nice_level);
357
$self->set('NO_AUTO_BUILD', \@no_auto_build)
359
$self->set('NO_BUILD_REGEX', $no_build_regex);
360
$self->set('NO_DETACH', $no_detach);
361
$self->set('BUILD_REGEX', $build_regex);
362
$self->set('NO_WARN_PATTERN', $no_warn_pattern);
363
$self->set('PIDFILE', $pidfile);
364
$self->set('PKG_LOG_KEEP', $pkg_log_keep);
365
$self->set('SECONDARY_DAEMON_THRESHOLD', $secondary_daemon_threshold);
366
$self->set('SHOULD_BUILD_MSGS', $should_build_msgs);
367
$self->set('SSH', $ssh);
368
$self->set('SSH_USER', $ssh_user);
369
$self->set('SSH_HOST', $ssh_host);
370
$self->set('SSH_OPTIONS', \@ssh_options)
372
$self->set('SSH_SOCKET', $ssh_socket);
373
$self->set('STATISTICS_MAIL', $statistics_mail);
374
$self->set('STATISTICS_PERIOD', $statistics_period);
375
$self->set('SUDO', $sudo);
376
$self->set('TAKE_FROM_DISTS', \@take_from_dists)
377
if (@take_from_dists);
378
$self->set('WANNA_BUILD_DBBASE', $wanna_build_dbbase);
379
$self->set('WANNA_BUILD_USER', $wanna_build_user);
380
$self->set('WARNING_AGE', $warning_age);
381
$self->set('WEAK_NO_AUTO_BUILD', \@weak_no_auto_build)
382
if (@weak_no_auto_build);
384
# Set here to allow user to override.
385
if (-t STDIN && -t STDOUT && $self->get('NO_DETACH')) {
386
$self->set('VERBOSE', 1);