]> git.proxmox.com Git - pve-container.git/commitdiff
prestart & poststop hook: init REST environment, e.g. for storage activation
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 3 May 2022 09:42:26 +0000 (11:42 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 4 May 2022 06:27:46 +0000 (08:27 +0200)
Initialize the basic CLI REST environment which is expected on some
PVE methods we may rely on.

This became a specific problem recently when adding better support
for external and/or multiple ceph RBD clusters on a PVE system in
commit cfe46e2d4a97a83f1bbe6ad656e6416399309ba2 from pve-storage,
which added a PVE::Rados call to get the underlying cluster FSID
required to build the /dev-mapped RBD path, and PVE::Rados
requires a initialized RPC/REST environment.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Suggested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/lxc-pve-poststop-hook
src/lxc-pve-prestart-hook

index 0fdd49ea4482a749083f99ca4ba801142c40a98a..2fe97ec89e814059083b7a65238db3b4fcb443f4 100755 (executable)
@@ -12,6 +12,7 @@ use PVE::LXC::Config;
 use PVE::LXC::Tools;
 use PVE::LXC;
 use PVE::Network;
+use PVE::RESTEnvironment;
 use PVE::Storage;
 use PVE::Tools;
 
@@ -20,6 +21,8 @@ PVE::LXC::Tools::lxc_hook('post-stop', 'lxc', sub {
 
     return undef if ! -f PVE::LXC::Config->config_file($vmid);
 
+    PVE::RESTEnvironment->setup_default_cli_env();
+
     my $conf = PVE::LXC::Config->load_config($vmid);
 
     my $storage_cfg = PVE::Storage::config();
index 0a76aee90ed36837dcda4a269d784427404b6889..2911e1be7bb7587eb0e820a4cc3083efa3bc1cd8 100755 (executable)
@@ -15,6 +15,7 @@ use PVE::LXC::Config;
 use PVE::LXC::Setup;
 use PVE::LXC::Tools;
 use PVE::LXC;
+use PVE::RESTEnvironment;
 use PVE::SafeSyslog;
 use PVE::Storage;
 use PVE::Syscall qw(:fsmount);
@@ -39,6 +40,8 @@ PVE::LXC::Tools::lxc_hook('pre-start', 'lxc', sub {
 
     PVE::Cluster::check_cfs_quorum(); # only start if we have quorum
 
+    PVE::RESTEnvironment->setup_default_cli_env();
+
     return undef if ! -f PVE::LXC::Config->config_file($vmid);
 
     my $conf = PVE::LXC::Config->load_config($vmid);