}
}
+my $randomize_crontab = sub {
+ my ($self, $conf) = @_;
+
+ my $rootdir = $self->{rootdir};
+
+ my @files = <$rootdir/etc/cron.d/*>;
+
+ my $crontab_fn = "$rootdir/etc/crontab";
+ unshift @files, $crontab_fn if -f $crontab_fn;
+
+ foreach my $filename (@files) {
+ my $data = PVE::Tools::file_get_contents($filename);
+ my $new = '';
+ foreach my $line (split(/\n/, $data)) {
+ # we only randomize minutes for root crontab entries
+ if ($line =~ m/^\d+(\s+\S+\s+\S+\s+\S+\s+\S+\s+root\s+\S.*)$/) {
+ my $rest = $1;
+ my $min = int(rand()*59);
+ $new .= "$min$rest\n";
+ } else {
+ $new .= "$line\n";
+ }
+ }
+ PVE::Tools::file_set_contents($filename, $new);
+ }
+};
+
sub pre_start_hook {
my ($self, $conf) = @_;
my ($self, $conf, $root_password) = @_;
$self->template_fixup($conf);
+
+ &$randomize_crontab($self, $conf);
+
$self->set_user_password($conf, 'root', $root_password);
$self->setup_init($conf);
$self->setup_network($conf);
for (my $i = 0; $i < 2; $i++) {
# run tests twice, to make sure scripts are idempotent
+ srand(0);
$lxc_setup->post_create_hook('$TEST$ABCDEF');
- my @testfiles = qw(/etc/hostname /etc/hosts /etc/inittab /etc/network/interfaces /etc/resolv.conf /etc/passwd /etc/shadow /etc/sysconfig/network /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/ifcfg-eth2 /etc/sysconfig/network-scripts/ifcfg-eth3 /etc/init/start-ttys.conf /etc/init/tty.conf /etc/init/power-status-changed.conf /etc/securetty);
+ my @testfiles = qw(/etc/hostname /etc/hosts /etc/inittab /etc/network/interfaces /etc/resolv.conf /etc/passwd /etc/shadow /etc/sysconfig/network /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/ifcfg-eth2 /etc/sysconfig/network-scripts/ifcfg-eth3 /etc/init/start-ttys.conf /etc/init/tty.conf /etc/init/power-status-changed.conf /etc/securetty /etc/crontab);
foreach my $fn (@testfiles) {
next if !-f "$testdir/$fn.exp";
test_file("$testdir/$fn.exp", "$rootfs/$fn");
--- /dev/null
+# /etc/crontab: system-wide crontab
+# Unlike any other crontab you don't have to run the `crontab'
+# command to install the new version when you edit this file
+# and files in /etc/cron.d. These files also have username fields,
+# that none of the other crontabs do.
+
+SHELL=/bin/sh
+PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+
+# m h dom mon dow user command
+17 * * * * root cd / && run-parts --report /etc/cron.hourly
+25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
+47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
+52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
+#
--- /dev/null
+# /etc/crontab: system-wide crontab
+# Unlike any other crontab you don't have to run the `crontab'
+# command to install the new version when you edit this file
+# and files in /etc/cron.d. These files also have username fields,
+# that none of the other crontabs do.
+
+SHELL=/bin/sh
+PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+
+# m h dom mon dow user command
+10 * * * * root cd / && run-parts --report /etc/cron.hourly
+44 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
+5 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
+51 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
+#