]>
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_file
( $vmid );
65 my $conf = PVE
:: LXC
:: load_config
( $vmid );
66 PVE
:: LXC
:: check_lock
( $conf ) if ! $ENV { PVE_SKIPLOCK
};
68 my $storage_cfg = PVE
:: Storage
:: config
();
70 my $vollist = PVE
:: LXC
:: get_vm_volumes
( $conf );
71 my $loopdevlist = PVE
:: LXC
:: get_vm_volumes
( $conf, 'rootfs' );
73 PVE
:: Storage
:: activate_volumes
( $storage_cfg, $vollist );
75 my $rootdir = $param ->{ rootfs
};
77 my $setup_mountpoint = sub {
78 my ( $ms, $mountpoint ) = @_ ;
80 #return if $ms eq 'rootfs';
81 PVE
:: LXC
:: mountpoint_mount
( $mountpoint, $rootdir, $storage_cfg );
84 my $setup_cgroup_device = sub {
85 my ( $ms, $mountpoint ) = @_ ;
87 my $volid = $mountpoint ->{ volume
};
88 return if ! $volid || $volid !~ m
|^ /dev/ .+|;
90 my $path = PVE
:: LXC
:: mountpoint_mount_path
( $mountpoint, $storage_cfg );
92 my ( undef , undef , $mode, undef , undef , undef , $rdev ) = stat ( $path );
93 if ( $mode && S_ISBLK
( $mode ) && $rdev ) {
94 my $major = int ( $rdev / 0x100 );
95 my $minor = $rdev % 0x100 ;
96 if ( $major != 7 ) { # must not be a loop device
97 PVE
:: Tools
:: run_command
([ 'mknod' , '-m' , '666' , " $rootdir$path " , 'b' , $major, $minor ]);
98 PVE
:: LXC
:: write_cgroup_value
( "devices" , $vmid, "devices.allow" , "b ${major}:${minor} rwm" );
103 PVE
:: LXC
:: foreach_mountpoint
( $conf, $setup_mountpoint );
105 PVE
:: LXC
:: foreach_mountpoint
( $conf, $setup_cgroup_device );
107 my $lxc_setup = PVE
:: LXC
:: Setup-
> new ( $conf, $rootdir );
108 $lxc_setup -> pre_start_hook ();
113 push @ARGV, 'help' if ! scalar ( @ARGV );
117 if (( scalar ( @ARGV ) == 3 ) && ( $ARGV [ 1 ] eq 'lxc' ) && ( $ARGV [ 2 ] eq 'pre-start' )) {
118 $param ->{ name
} = $ENV { 'LXC_NAME' };
119 die "got wrong name" if $param ->{ name
} ne $ARGV [ 0 ];
121 $param ->{ path
} = $ENV { 'LXC_CONFIG_FILE' };
122 $param ->{ rootfs
} = $ENV { 'LXC_ROOTFS_PATH' };
128 our $cmddef = [ __PACKAGE__
, 'lxc-pve-prestart-hook' , [], $param ];
130 __PACKAGE__-
> run_cli_handler ();