]> git.proxmox.com Git - pve-container.git/blame - src/lxc-pve-mount-hook
debian setup: dhcp, manual and unmanaged network
[pve-container.git] / src / lxc-pve-mount-hook
CommitLineData
93285df8
DM
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use POSIX;
6use File::Path;
7
8use PVE::SafeSyslog;
9use PVE::Tools;
10use PVE::Cluster;
11use PVE::INotify;
12use PVE::RPCEnvironment;
13use PVE::JSONSchema qw(get_standard_option);
14use PVE::CLIHandler;
15use PVE::Storage;
16use PVE::LXC;
17use PVE::LXCSetup;
18use Data::Dumper;
19
20use base qw(PVE::CLIHandler);
21
22$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
23
24initlog ('lxc-pve-mount-hook');
25
26die "please run as root\n" if $> != 0;
27
28PVE::INotify::inotify_init();
29
30my $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
37my $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 => {
4fc1b360
DM
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>/config (else it is just a NOP).",
49 type => 'string',
50 pattern => '\S+',
51 maxLength => 64,
52 },
93285df8
DM
53 path => {
54 description => "The path to the container configuration directory (LXC internal argument - do not pass manually!).",
55 type => 'string',
56 },
57 rootfs => {
58 description => "The path to the container's rootfs (LXC internal argument - do not pass manually!)",
59 type => 'string',
60 },
61 },
62 },
63 returns => { type => 'null' },
64
65 code => sub {
66 my ($param) = @_;
67
68 my $private = $param->{rootfs};
69
4fc1b360
DM
70 return undef if $param->{name} !~ m/^\d+$/;
71 return undef if $param->{path} !~ m!^/etc/pve/lxc/$param->{name}/config$!;
93285df8
DM
72
73 my $raw = PVE::Tools::file_get_contents($param->{path});
74 my $conf = PVE::LXC::parse_lxc_config($param->{path}, $raw);
75
5b4657d0
DM
76 my $mountpoint = $ENV{LXC_ROOTFS_MOUNT};
77
78 my $lxc_setup = PVE::LXCSetup->new($conf, $mountpoint);
d66768a2 79 $lxc_setup->pre_start_hook();
5b4657d0 80
93285df8
DM
81 return undef;
82 }});
83
84
85push @ARGV, 'help' if !scalar(@ARGV);
86
87my $param = {};
88
89if ((scalar(@ARGV) == 1) && ($ARGV[0] eq 'printmanpod') ||
90 ($ARGV[0] eq 'verifyapi')) {
91 # OK
92} elsif ((scalar(@ARGV) == 3) && ($ARGV[1] eq 'lxc') && ($ARGV[2] eq 'mount')) {
93 $param->{name} = $ENV{'LXC_NAME'};
94 die "got wrong name" if $param->{name} ne $ARGV[0];
5b4657d0 95
93285df8
DM
96 $param->{path} = $ENV{'LXC_CONFIG_FILE'};
97 $param->{rootfs} = $ENV{'LXC_ROOTFS_PATH'};
98 @ARGV = ();
99} else {
100 @ARGV = ('help');
101}
102
103my $cmddef = [ __PACKAGE__, 'lxc-pve-mount-hook', [], $param];
104
105PVE::CLIHandler::handle_simple_cmd($cmddef, \@ARGV, undef, $0);
106
107exit 0;
108
109__END__
110
111=head1 NAME
112
113lxc-pve - LXC mount hook for Proxmox VE
114
115=head1 SYNOPSIS
116
117=include synopsis
118
119=head1 DESCRIPTION
120
4fc1b360 121This mount hook sets the network and hostname for pve container.
93285df8
DM
122
123=head1 SEE ALSO
124
125lct(1)
126
127=include pve_copyright