]>
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) ;
25 use base
qw(PVE::CLIHandler) ;
27 __PACKAGE__-
> register_method ({
28 name
=> 'lxc-pve-prestart-hook' ,
29 path
=> 'lxc-pve-prestart-hook' ,
31 description
=> "Create a new container root directory." ,
33 additionalProperties
=> 0 ,
36 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)." ,
42 description
=> "The path to the container configuration directory (LXC internal argument - do not pass manually!)." ,
46 description
=> "The path to the container's rootfs (LXC internal argument - do not pass manually!)" ,
51 returns
=> { type
=> 'null' },
56 return undef if $param ->{ name
} !~ m/^\d+$/ ;
58 my $vmid = $param ->{ name
};
59 my $skiplock_flag_fn = "/run/lxc/skiplock- $vmid " ;
60 my $skiplock = 1 if - e
$skiplock_flag_fn ;
61 unlink $skiplock_flag_fn if $skiplock ;
63 PVE
:: Cluster
:: check_cfs_quorum
(); # only start if we have quorum
65 return undef if ! - f PVE
:: LXC
:: Config-
> config_file ( $vmid );
67 my $conf = PVE
:: LXC
:: Config-
> load_config ( $vmid );
68 if (! $skiplock && ! PVE
:: LXC
:: Config-
> has_lock ( $conf, 'mounted' )) {
69 PVE
:: LXC
:: Config-
> check_lock ( $conf );
72 my $storage_cfg = PVE
:: Storage
:: config
();
74 my $vollist = PVE
:: LXC
:: Config-
> get_vm_volumes ( $conf );
75 my $loopdevlist = PVE
:: LXC
:: Config-
> get_vm_volumes ( $conf, 'rootfs' );
77 PVE
:: Storage
:: activate_volumes
( $storage_cfg, $vollist );
79 my $rootdir = $param ->{ rootfs
};
81 # Delete any leftover reboot-trigger file
82 unlink ( "/var/lib/lxc/ $vmid/reboot " );
84 my $devlist_file = "/var/lib/lxc/ $vmid/devices " ;
88 my $setup_mountpoint = sub {
89 my ( $ms, $mountpoint ) = @_ ;
91 #return if $ms eq 'rootfs';
92 my ( undef , undef , $dev ) = PVE
:: LXC
:: mountpoint_mount
( $mountpoint, $rootdir, $storage_cfg );
93 push @$devices, $dev if $dev && $mountpoint ->{ quota
};
96 # Unmount first when the user mounted the container with "pct mount".
98 PVE
:: Tools
:: run_command
([ 'umount' , '--recursive' , $rootdir ], outfunc
=> sub {}, errfunc
=> sub {});
101 PVE
:: LXC
:: Config-
> foreach_mountpoint ( $conf, $setup_mountpoint );
103 my $lxc_setup = PVE
:: LXC
:: Setup-
> new ( $conf, $rootdir );
104 $lxc_setup -> pre_start_hook ();
108 foreach my $dev ( @$devices ) {
109 my ( $mode, $rdev ) = ( stat ( $dev ))[ 2 , 6 ];
110 next if ! $mode || ! S_ISBLK
( $mode ) || ! $rdev ;
111 my $major = PVE
:: Tools
:: dev_t_major
( $rdev );
112 my $minor = PVE
:: Tools
:: dev_t_minor
( $rdev );
113 $devlist .= "b: $major : $minor : $dev\n " ;
115 PVE
:: Tools
:: file_set_contents
( $devlist_file, $devlist );
121 push @ARGV, 'help' if ! scalar ( @ARGV );
125 if (( scalar ( @ARGV ) == 3 ) && ( $ARGV [ 1 ] eq 'lxc' ) && ( $ARGV [ 2 ] eq 'pre-start' )) {
126 $param ->{ name
} = $ENV { 'LXC_NAME' };
127 die "got wrong name" if $param ->{ name
} ne $ARGV [ 0 ];
129 $param ->{ path
} = $ENV { 'LXC_CONFIG_FILE' };
130 $param ->{ rootfs
} = $ENV { 'LXC_ROOTFS_PATH' };
136 our $cmddef = [ __PACKAGE__
, 'lxc-pve-prestart-hook' , [], $param ];
138 __PACKAGE__-
> run_cli_handler ();