use PVE::ProcFSTools;
use PVE::Syscall;
use PVE::LXC::Config;
+use PVE::GuestHelpers;
use Time::HiRes qw (gettimeofday);
} elsif ($opt eq 'features') {
# For now this is restricted to root@pam
raise_perm_exc("changing feature flags is only allowed for root\@pam");
+ } elsif ($opt eq 'hookscript') {
+ # For now this is restricted to root@pam
+ raise_perm_exc("changing the hookscript is only allowed for root\@pam");
} else {
$rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.Options']);
}
my $cmd = ['systemctl', 'start', "pve-container\@$vmid"];
+ PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'pre-start', 1);
eval { PVE::Tools::run_command($cmd); };
if (my $err = $@) {
unlink $skiplock_flag_fn;
die $err;
}
+ PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-start');
return;
}
die "failed to open container ${vmid}'s command socket: $!\n";
}
+ my $conf = PVE::LXC::Config->load_config($vmid);
+ PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'pre-stop');
+
# Stop the container:
my $cmd = ['lxc-stop', '-n', $vmid];
use PVE::AbstractConfig;
use PVE::Cluster qw(cfs_register_file);
+use PVE::GuestHelpers;
use PVE::INotify;
use PVE::JSONSchema qw(get_standard_option);
use PVE::Tools;
format => $features_desc,
description => "Allow containers access to advanced features.",
},
+ hookscript => {
+ optional => 1,
+ type => 'string',
+ format => 'pve-volume-id',
+ description => 'Script that will be exectued during various steps in the containers lifetime.',
+ },
};
my $valid_lxc_conf_keys = {
delete $conf->{$opt};
PVE::LXC::write_cgroup_value("memory", $vmid,
"memory.memsw.limit_in_bytes", -1);
- } elsif ($opt eq 'description' || $opt eq 'onboot' || $opt eq 'startup') {
+ } elsif ($opt eq 'description' || $opt eq 'onboot' || $opt eq 'startup' || $opt eq 'hookscript') {
delete $conf->{$opt};
} elsif ($opt eq 'nameserver' || $opt eq 'searchdomain' ||
$opt eq 'tty' || $opt eq 'console' || $opt eq 'cmode') {
} elsif ($opt eq 'features') {
next if $hotplug_error->($opt);
$conf->{$opt} = $value;
+ } elsif ($opt eq 'hookscript') {
+ PVE::GuestHelpers::check_hookscript($value);
+ $conf->{$opt} = $value;
} else {
die "implement me: $opt";
}
use PVE::Storage;
use PVE::Storage::Plugin;
use PVE::LXC;
+use PVE::GuestHelpers;
use Data::Dumper;
use base qw(PVE::CLIHandler);
exit(1);
}
+ PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-stop');
+
return undef;
}});