]>
Commit | Line | Data |
---|---|---|
32e6d659 AD |
1 | #!/usr/bin/perl |
2 | ||
3 | use strict; | |
4 | use warnings; | |
4ed2b825 | 5 | |
d6811d3f | 6 | exit 0 if $ENV{LXC_NAME} && $ENV{LXC_NAME} !~ /^\d+$/; |
4ed2b825 | 7 | |
32e6d659 AD |
8 | use POSIX; |
9 | use File::Path; | |
10 | ||
11 | use PVE::SafeSyslog; | |
12 | use PVE::Tools; | |
13 | use PVE::Cluster; | |
14 | use PVE::INotify; | |
15 | use PVE::RPCEnvironment; | |
16 | use PVE::JSONSchema qw(get_standard_option); | |
17 | use PVE::CLIHandler; | |
18 | use PVE::Storage; | |
19 | use PVE::Storage::Plugin; | |
20 | use PVE::LXC; | |
32e6d659 AD |
21 | use Data::Dumper; |
22 | ||
23 | use base qw(PVE::CLIHandler); | |
24 | ||
25 | $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin'; | |
26 | ||
27 | initlog ('lxc-pve-poststop-hook'); | |
28 | ||
29 | die "please run as root\n" if $> != 0; | |
30 | ||
31 | PVE::INotify::inotify_init(); | |
32 | ||
33 | my $rpcenv = PVE::RPCEnvironment->init('cli'); | |
34 | $rpcenv->set_language($ENV{LANG}); | |
35 | $rpcenv->set_user('root@pam'); | |
36 | ||
37 | # we cannot use cfs_read here (permission problem) | |
38 | #$rpcenv->init_request(); | |
39 | ||
40 | my $nodename = PVE::INotify::nodename(); | |
41 | ||
42 | __PACKAGE__->register_method ({ | |
43 | name => 'lxc-pve-poststop-hook', | |
44 | path => 'lxc-pve-poststop-hook', | |
45 | method => 'GET', | |
46 | description => "vm_stop_cleanup.", | |
47 | parameters => { | |
48 | additionalProperties => 0, | |
49 | properties => { | |
50 | name => { | |
c0c77476 | 51 | 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).", |
32e6d659 AD |
52 | type => 'string', |
53 | pattern => '\S+', | |
54 | maxLength => 64, | |
55 | } | |
56 | }, | |
57 | }, | |
58 | returns => { type => 'null' }, | |
59 | ||
60 | code => sub { | |
61 | my ($param) = @_; | |
62 | ||
32e6d659 AD |
63 | return undef if $param->{name} !~ m/^\d+$/; |
64 | ||
2914ad9b | 65 | my $vmid = $param->{name}; |
32e6d659 | 66 | |
2914ad9b | 67 | return undef if ! -f PVE::LXC::config_file($vmid); |
32e6d659 | 68 | |
2914ad9b | 69 | my $conf = PVE::LXC::load_config($vmid); |
32e6d659 | 70 | |
2914ad9b | 71 | my $storage_cfg = PVE::Storage::config(); |
32e6d659 | 72 | |
2914ad9b | 73 | PVE::LXC::vm_stop_cleanup($storage_cfg, $vmid, $conf); |
32e6d659 AD |
74 | |
75 | return undef; | |
76 | }}); | |
77 | ||
78 | ||
79 | push @ARGV, 'help' if !scalar(@ARGV); | |
80 | ||
81 | my $param = {}; | |
82 | ||
83 | if ((scalar(@ARGV) == 1) && ($ARGV[0] eq 'printmanpod') || | |
84 | ($ARGV[0] eq 'verifyapi')) { | |
85 | # OK | |
86 | } elsif ((scalar(@ARGV) == 3) && ($ARGV[1] eq 'lxc') && ($ARGV[2] eq 'post-stop')) { | |
87 | $param->{name} = $ENV{'LXC_NAME'}; | |
88 | die "got wrong name" if $param->{name} ne $ARGV[0]; | |
89 | ||
90 | @ARGV = (); | |
91 | } else { | |
92 | @ARGV = ('help'); | |
93 | } | |
94 | ||
95 | my $cmddef = [ __PACKAGE__, 'lxc-pve-poststop-hook', [], $param]; | |
96 | ||
97 | PVE::CLIHandler::handle_simple_cmd($cmddef, \@ARGV, undef, $0); | |
98 | ||
99 | exit 0; | |
100 | ||
101 | __END__ | |
102 | ||
103 | =head1 NAME | |
104 | ||
105 | lxc-pve - LXC post stop hook for Proxmox VE | |
106 | ||
107 | =head1 SYNOPSIS | |
108 | ||
109 | =include synopsis | |
110 | ||
111 | =head1 DESCRIPTION | |
112 | ||
113 | This post stop hook detach loop devices and deactivate volumes for pve container. | |
114 | ||
115 | =head1 SEE ALSO | |
116 | ||
117 | lct(1) | |
118 | ||
119 | =include pve_copyright |