]>
git.proxmox.com Git - pve-container.git/blob - src/lxc-pve-prestart-hook
3 package lxc_pve_prestart_hook
;
8 exit 0 if $ENV { LXC_NAME
} && $ENV { LXC_NAME
} !~ /^\d+$/ ;
18 use PVE
:: RPCEnvironment
;
19 use PVE
:: JSONSchema
qw(get_standard_option) ;
26 use base
qw(PVE::CLIHandler) ;
28 __PACKAGE__-
> register_method ({
29 name
=> 'lxc-pve-prestart-hook' ,
30 path
=> 'lxc-pve-prestart-hook' ,
32 description
=> "Create a new container root directory." ,
34 additionalProperties
=> 0 ,
37 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)." ,
43 description
=> "The path to the container configuration directory (LXC internal argument - do not pass manually!)." ,
47 description
=> "The path to the container's rootfs (LXC internal argument - do not pass manually!)" ,
52 returns
=> { type
=> 'null' },
57 return undef if $param ->{ name
} !~ m/^\d+$/ ;
59 my $vmid = $param ->{ name
};
61 PVE
:: Cluster
:: check_cfs_quorum
(); # only start if we have quorum
63 return undef if ! - f PVE
:: LXC
:: Config-
> config_file ( $vmid );
65 my $conf = PVE
:: LXC
:: Config-
> load_config ( $vmid );
66 if (! $ENV { PVE_SKIPLOCK
} && ! PVE
:: LXC
:: Config-
> has_lock ( $conf, 'mounted' )) {
67 PVE
:: LXC
:: Config-
> check_lock ( $conf );
70 my $storage_cfg = PVE
:: Storage
:: config
();
72 my $vollist = PVE
:: LXC
:: get_vm_volumes
( $conf );
73 my $loopdevlist = PVE
:: LXC
:: get_vm_volumes
( $conf, 'rootfs' );
75 PVE
:: Storage
:: activate_volumes
( $storage_cfg, $vollist );
77 my $rootdir = $param ->{ rootfs
};
79 my $devlist_file = "/var/lib/lxc/ $vmid/devices " ;
83 my $setup_mountpoint = sub {
84 my ( $ms, $mountpoint ) = @_ ;
86 #return if $ms eq 'rootfs';
87 my ( undef , undef , $dev ) = PVE
:: LXC
:: mountpoint_mount
( $mountpoint, $rootdir, $storage_cfg );
88 push @$devices, $dev if $dev && $mountpoint ->{ quota
};
91 PVE
:: LXC
:: foreach_mountpoint
( $conf, $setup_mountpoint );
93 my $lxc_setup = PVE
:: LXC
:: Setup-
> new ( $conf, $rootdir );
94 $lxc_setup -> pre_start_hook ();
98 foreach my $dev ( @$devices ) {
99 my ( $mode, $rdev ) = ( stat ( $dev ))[ 2 , 6 ];
100 next if ! $mode || ! S_ISBLK
( $mode ) || ! $rdev ;
101 my $major = int ( $rdev / 0x100 );
102 my $minor = $rdev % 0x100 ;
103 $devlist .= "b: $major : $minor : $dev\n " ;
105 PVE
:: Tools
:: file_set_contents
( $devlist_file, $devlist );
111 push @ARGV, 'help' if ! scalar ( @ARGV );
115 if (( scalar ( @ARGV ) == 3 ) && ( $ARGV [ 1 ] eq 'lxc' ) && ( $ARGV [ 2 ] eq 'pre-start' )) {
116 $param ->{ name
} = $ENV { 'LXC_NAME' };
117 die "got wrong name" if $param ->{ name
} ne $ARGV [ 0 ];
119 $param ->{ path
} = $ENV { 'LXC_CONFIG_FILE' };
120 $param ->{ rootfs
} = $ENV { 'LXC_ROOTFS_PATH' };
126 our $cmddef = [ __PACKAGE__
, 'lxc-pve-prestart-hook' , [], $param ];
128 __PACKAGE__-
> run_cli_handler ();