]>
git.proxmox.com Git - pve-container.git/blob - src/lxc-pve-poststop-hook
3 package lxc_pve_poststop_hook
;
8 exit 0 if $ENV { LXC_NAME
} && $ENV { LXC_NAME
} !~ /^\d+$/ ;
17 use PVE
:: RPCEnvironment
;
18 use PVE
:: JSONSchema
qw(get_standard_option) ;
21 use PVE
:: Storage
:: Plugin
;
25 use base
qw(PVE::CLIHandler) ;
27 __PACKAGE__-
> register_method ({
28 name
=> 'lxc-pve-poststop-hook' ,
29 path
=> 'lxc-pve-poststop-hook' ,
31 description
=> "vm_stop_cleanup." ,
33 additionalProperties
=> 0 ,
36 description
=> "The container name. This hook is only active for containers using numeric IDs, where configuration is stored on /etc/pve/lxc/<name>.conf (else it is just a NOP)." ,
43 returns
=> { type
=> 'null' },
48 return undef if $param ->{ name
} !~ m/^\d+$/ ;
50 my $vmid = $param ->{ name
};
52 return undef if ! - f PVE
:: LXC
:: Config-
> config_file ( $vmid );
54 my $conf = PVE
:: LXC
:: Config-
> load_config ( $vmid );
56 my $storage_cfg = PVE
:: Storage
:: config
();
58 PVE
:: LXC
:: vm_stop_cleanup
( $storage_cfg, $vmid, $conf );
60 my $rootfs = $ENV { LXC_ROOTFS_PATH
};
61 die "Missing container root directory! \n " if ! $rootfs ;
62 PVE
:: Tools
:: run_command
([ 'umount' , '--recursive' , $rootfs ]);
64 # Because netlink is not a reliable protocol it can happen that lxc's
65 # link-deletion messages get lost (or end up being too early?)
66 for my $k ( keys %$conf ) {
67 next if $k !~ /^net(\d+)/ ;
69 my $net = PVE
:: LXC
:: Config-
> parse_lxc_network ( $conf ->{ $k });
70 next if $net ->{ type
} ne 'veth' ;
71 # veth_delete tests with '-d /sys/class/net/$name' before running the command
72 PVE
:: Network
:: veth_delete
( "veth${vmid}i $ind " );
75 my $target = $ENV { LXC_TARGET
};
76 if ( $target && $target eq 'reboot' ) {
77 # In order to make sure hot-plugged config changes aren't reverted
78 # to what the monitor initially loaded we need to stop the container
80 # Update the config and queue a restart of the pve-container@$vmid
81 # task, note that we must not block because we're part of the
82 # service cgroup systemd waits for to die before issuing the new
84 PVE
:: LXC
:: update_lxc_config
( $vmid, $conf );
85 # Tell the post-stop hook we want to be restarted.
86 open ( my $fh, '>' , "/var/lib/lxc/ $vmid/reboot " )
87 or die "failed to create reboot trigger file: $!\n " ;
89 # cause lxc to stop instead of rebooting
97 push @ARGV, 'help' if ! scalar ( @ARGV );
101 if (( scalar ( @ARGV ) == 3 ) && ( $ARGV [ 1 ] eq 'lxc' ) && ( $ARGV [ 2 ] eq 'post-stop' )) {
102 $param ->{ name
} = $ENV { 'LXC_NAME' };
103 die "got wrong name" if $param ->{ name
} ne $ARGV [ 0 ];
110 our $cmddef = [ __PACKAGE__
, 'lxc-pve-poststop-hook' , [], $param ];
112 __PACKAGE__-
> run_cli_handler ();