]> git.proxmox.com Git - pve-container.git/blob - src/lxc-pve-mount-hook
cc7c98b5abe47f8c32fa4ae08fdbad4b5cfd30ba
[pve-container.git] / src / lxc-pve-mount-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::LXC;
17 use PVE::LXCSetup;
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-mount-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-mount-hook',
41 path => 'lxc-pve-mount-hook',
42 method => 'GET',
43 description => "Create a new container root directory.",
44 parameters => {
45 additionalProperties => 0,
46 properties => {
47 name => get_standard_option('pve-vmid'),
48 path => {
49 description => "The path to the container configuration directory (LXC internal argument - do not pass manually!).",
50 type => 'string',
51 },
52 rootfs => {
53 description => "The path to the container's rootfs (LXC internal argument - do not pass manually!)",
54 type => 'string',
55 },
56 },
57 },
58 returns => { type => 'null' },
59
60 code => sub {
61 my ($param) = @_;
62
63 my $private = $param->{rootfs};
64
65 die "got strange path '$param->{path}'\n"
66 if $param->{path} !~ m!^/etc/pve/lxc/$param->{name}/config$!;
67
68 my $raw = PVE::Tools::file_get_contents($param->{path});
69 my $conf = PVE::LXC::parse_lxc_config($param->{path}, $raw);
70
71 my $lxc_setup = PVE::LXCSetup->new($conf);
72 $lxc_setup->pre_start_hook();
73
74 return undef;
75 }});
76
77
78 push @ARGV, 'help' if !scalar(@ARGV);
79
80 my $param = {};
81
82 if ((scalar(@ARGV) == 1) && ($ARGV[0] eq 'printmanpod') ||
83 ($ARGV[0] eq 'verifyapi')) {
84 # OK
85 } elsif ((scalar(@ARGV) == 3) && ($ARGV[1] eq 'lxc') && ($ARGV[2] eq 'mount')) {
86 $param->{name} = $ENV{'LXC_NAME'};
87 die "got wrong name" if $param->{name} ne $ARGV[0];
88
89 $param->{path} = $ENV{'LXC_CONFIG_FILE'};
90 $param->{rootfs} = $ENV{'LXC_ROOTFS_PATH'};
91 @ARGV = ();
92 } else {
93 @ARGV = ('help');
94 }
95
96 my $cmddef = [ __PACKAGE__, 'lxc-pve-mount-hook', [], $param];
97
98 PVE::CLIHandler::handle_simple_cmd($cmddef, \@ARGV, undef, $0);
99
100 exit 0;
101
102 __END__
103
104 =head1 NAME
105
106 lxc-pve - LXC mount hook for Proxmox VE
107
108 =head1 SYNOPSIS
109
110 =include synopsis
111
112 =head1 DESCRIPTION
113
114 This mount hook sets the network and hostname for the container.
115
116 =head1 SEE ALSO
117
118 lct(1)
119
120 =include pve_copyright