]>
git.proxmox.com Git - pve-container.git/blob - src/lxc-pve-prestart-hook
8ff46721f5033a53966e360648a7073012b4996d
12 use PVE
:: RPCEnvironment
;
13 use PVE
:: JSONSchema
qw(get_standard_option) ;
19 use base
qw(PVE::CLIHandler) ;
21 $ENV { 'PATH' } = '/sbin:/bin:/usr/sbin:/usr/bin' ;
23 initlog
( 'lxc-pve-prestart-hook' );
25 die "please run as root \n " if $> != 0 ;
27 PVE
:: INotify
:: inotify_init
();
29 my $rpcenv = PVE
:: RPCEnvironment-
> init ( 'cli' );
30 $rpcenv -> set_language ( $ENV { LANG
});
31 $rpcenv -> set_user ( 'root @pam ' );
33 # we cannot use cfs_read here (permission problem)
34 #$rpcenv->init_request();
36 my $nodename = PVE
:: INotify
:: nodename
();
38 __PACKAGE__-
> register_method ({
39 name
=> 'lxc-pve-prestart-hook' ,
40 path
=> 'lxc-pve-prestart-hook' ,
42 description
=> "Create a new container root directory." ,
44 additionalProperties
=> 0 ,
47 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)." ,
53 description
=> "The path to the container configuration directory (LXC internal argument - do not pass manually!)." ,
57 description
=> "The path to the container's rootfs (LXC internal argument - do not pass manually!)" ,
62 returns
=> { type
=> 'null' },
67 return undef if $param ->{ name
} !~ m/^\d+$/ ;
69 my $rootdir = $ENV { LXC_ROOTFS_MOUNT
};
71 my $vmid = $param ->{ name
};
73 PVE
:: Cluster
:: check_cfs_quorum
(); # only start if we have quorum
75 return undef if ! - f PVE
:: LXC
:: config_file
( $vmid );
77 my $conf = PVE
:: LXC
:: load_config
( $vmid );
79 my $storage_cfg = PVE
:: Storage
:: config
();
84 PVE
:: LXC
:: foreach_mountpoint
( $conf, sub {
85 my ( $ms, $mountpoint ) = @_ ;
87 my $volid = $mountpoint ->{ volume
};
88 return if ! $volid || $volid =~ m
|^ /dev/ .+|;
89 push @$vollist, $volid ;
90 push @$loopdevlist, $volid if $ms ne 'rootfs' ;
93 PVE
:: Storage
:: activate_volumes
( $storage_cfg, $vollist );
94 PVE
:: LXC
:: attach_loops
( $storage_cfg, $loopdevlist );
99 push @ARGV, 'help' if ! scalar ( @ARGV );
103 if (( scalar ( @ARGV ) == 1 ) && ( $ARGV [ 0 ] eq 'printmanpod' ) ||
104 ( $ARGV [ 0 ] eq 'verifyapi' )) {
106 } elsif (( scalar ( @ARGV ) == 3 ) && ( $ARGV [ 1 ] eq 'lxc' ) && ( $ARGV [ 2 ] eq 'pre-start' )) {
107 $param ->{ name
} = $ENV { 'LXC_NAME' };
108 die "got wrong name" if $param ->{ name
} ne $ARGV [ 0 ];
110 $param ->{ path
} = $ENV { 'LXC_CONFIG_FILE' };
111 $param ->{ rootfs
} = $ENV { 'LXC_ROOTFS_PATH' };
117 my $cmddef = [ __PACKAGE__
, 'lxc-pve-prestart-hook' , [], $param ];
119 PVE
:: CLIHandler
:: handle_simple_cmd
( $cmddef, \
@ARGV, undef , $0 );
127 lxc-pve - LXC pre-start hook for Proxmox VE
135 This mount hook activate storage and volumes for pve container.
141 =include pve_copyright