]> git.proxmox.com Git - pve-container.git/blame - src/lxc-pve-poststop-hook
use PVE::Cluster::complete_next_vmid
[pve-container.git] / src / lxc-pve-poststop-hook
CommitLineData
32e6d659
AD
1#!/usr/bin/perl
2
3use strict;
4use warnings;
4ed2b825 5
d6811d3f 6exit 0 if $ENV{LXC_NAME} && $ENV{LXC_NAME} !~ /^\d+$/;
4ed2b825 7
32e6d659
AD
8use POSIX;
9use File::Path;
10
11use PVE::SafeSyslog;
12use PVE::Tools;
13use PVE::Cluster;
14use PVE::INotify;
15use PVE::RPCEnvironment;
16use PVE::JSONSchema qw(get_standard_option);
17use PVE::CLIHandler;
18use PVE::Storage;
19use PVE::Storage::Plugin;
20use PVE::LXC;
32e6d659
AD
21use Data::Dumper;
22
23use base qw(PVE::CLIHandler);
24
25$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
26
27initlog ('lxc-pve-poststop-hook');
28
29die "please run as root\n" if $> != 0;
30
31PVE::INotify::inotify_init();
32
33my $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
40my $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
79push @ARGV, 'help' if !scalar(@ARGV);
80
81my $param = {};
82
83if ((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
95my $cmddef = [ __PACKAGE__, 'lxc-pve-poststop-hook', [], $param];
96
97PVE::CLIHandler::handle_simple_cmd($cmddef, \@ARGV, undef, $0);
98
99exit 0;
100
101__END__
102
103=head1 NAME
104
105lxc-pve - LXC post stop hook for Proxmox VE
106
107=head1 SYNOPSIS
108
109=include synopsis
110
111=head1 DESCRIPTION
112
113This post stop hook detach loop devices and deactivate volumes for pve container.
114
115=head1 SEE ALSO
116
117lct(1)
118
119=include pve_copyright