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