]>
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
};
60 my $skiplock_flag_fn = "/run/lxc/skiplock- $vmid " ;
61 my $skiplock = 1 if - e
$skiplock_flag_fn ;
62 unlink $skiplock_flag_fn if $skiplock ;
64 PVE
:: Cluster
:: check_cfs_quorum
(); # only start if we have quorum
66 return undef if ! - f PVE
:: LXC
:: Config-
> config_file ( $vmid );
68 my $conf = PVE
:: LXC
:: Config-
> load_config ( $vmid );
69 if (! $skiplock && ! PVE
:: LXC
:: Config-
> has_lock ( $conf, 'mounted' )) {
70 PVE
:: LXC
:: Config-
> check_lock ( $conf );
73 my $storage_cfg = PVE
:: Storage
:: config
();
75 my $vollist = PVE
:: LXC
:: Config-
> get_vm_volumes ( $conf );
76 my $loopdevlist = PVE
:: LXC
:: Config-
> get_vm_volumes ( $conf, 'rootfs' );
78 PVE
:: Storage
:: activate_volumes
( $storage_cfg, $vollist );
80 my $rootdir = $param ->{ rootfs
};
82 # Delete any leftover reboot-trigger file
83 unlink ( "/var/lib/lxc/ $vmid/reboot " );
85 my $devlist_file = "/var/lib/lxc/ $vmid/devices " ;
89 my $setup_mountpoint = sub {
90 my ( $ms, $mountpoint ) = @_ ;
92 #return if $ms eq 'rootfs';
93 my ( undef , undef , $dev ) = PVE
:: LXC
:: mountpoint_mount
( $mountpoint, $rootdir, $storage_cfg );
94 push @$devices, $dev if $dev && $mountpoint ->{ quota
};
97 # Unmount first when the user mounted the container with "pct mount".
99 PVE
:: Tools
:: run_command
([ 'umount' , '--recursive' , $rootdir ], outfunc
=> sub {}, errfunc
=> sub {});
102 PVE
:: LXC
:: Config-
> foreach_mountpoint ( $conf, $setup_mountpoint );
104 my $lxc_setup = PVE
:: LXC
:: Setup-
> new ( $conf, $rootdir );
105 $lxc_setup -> pre_start_hook ();
109 foreach my $dev ( @$devices ) {
110 my ( $mode, $rdev ) = ( stat ( $dev ))[ 2 , 6 ];
111 next if ! $mode || ! S_ISBLK
( $mode ) || ! $rdev ;
112 my $major = int ( $rdev / 0x100 );
113 my $minor = $rdev % 0x100 ;
114 $devlist .= "b: $major : $minor : $dev\n " ;
116 PVE
:: Tools
:: file_set_contents
( $devlist_file, $devlist );
122 push @ARGV, 'help' if ! scalar ( @ARGV );
126 if (( scalar ( @ARGV ) == 3 ) && ( $ARGV [ 1 ] eq 'lxc' ) && ( $ARGV [ 2 ] eq 'pre-start' )) {
127 $param ->{ name
} = $ENV { 'LXC_NAME' };
128 die "got wrong name" if $param ->{ name
} ne $ARGV [ 0 ];
130 $param ->{ path
} = $ENV { 'LXC_CONFIG_FILE' };
131 $param ->{ rootfs
} = $ENV { 'LXC_ROOTFS_PATH' };
137 our $cmddef = [ __PACKAGE__
, 'lxc-pve-prestart-hook' , [], $param ];
139 __PACKAGE__-
> run_cli_handler ();