]>
git.proxmox.com Git - pve-container.git/blob - src/lxc-pve-prestart-hook
12 use PVE
:: RPCEnvironment
;
13 use PVE
:: JSONSchema
qw(get_standard_option) ;
20 use base
qw(PVE::CLIHandler) ;
22 $ENV { 'PATH' } = '/sbin:/bin:/usr/sbin:/usr/bin' ;
24 initlog
( 'lxc-pve-prestart-hook' );
26 die "please run as root \n " if $> != 0 ;
28 PVE
:: INotify
:: inotify_init
();
30 my $rpcenv = PVE
:: RPCEnvironment-
> init ( 'cli' );
31 $rpcenv -> set_language ( $ENV { LANG
});
32 $rpcenv -> set_user ( 'root @pam ' );
34 # we cannot use cfs_read here (permission problem)
35 #$rpcenv->init_request();
37 my $nodename = PVE
:: INotify
:: nodename
();
39 __PACKAGE__-
> register_method ({
40 name
=> 'lxc-pve-prestart-hook' ,
41 path
=> 'lxc-pve-prestart-hook' ,
43 description
=> "Create a new container root directory." ,
45 additionalProperties
=> 0 ,
48 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)." ,
54 description
=> "The path to the container configuration directory (LXC internal argument - do not pass manually!)." ,
58 description
=> "The path to the container's rootfs (LXC internal argument - do not pass manually!)" ,
63 returns
=> { type
=> 'null' },
68 return undef if $param ->{ name
} !~ m/^\d+$/ ;
70 my $rootdir = $ENV { LXC_ROOTFS_MOUNT
};
72 my $vmid = $param ->{ name
};
74 PVE
:: Cluster
:: check_cfs_quorum
(); # only start if we have quorum
76 return undef if ! - f PVE
:: LXC
:: config_file
( $vmid );
78 my $conf = PVE
:: LXC
:: load_config
( $vmid );
80 my $storage_cfg = PVE
:: Storage
:: config
();
82 PVE
:: LXC
:: foreach_mountpoint
( $conf, sub {
83 my ( $ms, $mountpoint ) = @_ ;
85 my $volid = $mountpoint ->{ volume
};
86 return if ! $volid || $volid =~ m
|^ /dev/ .+|;
88 PVE
:: Storage
:: activate_volumes
( $storage_cfg, [ $volid ]);
90 my ( $storage, $volname ) = PVE
:: Storage
:: parse_volume_id
( $volid );
91 my $scfg = PVE
:: Storage
:: storage_config
( $storage_cfg, $storage );
92 my ( $vtype, undef , undef , undef , undef , $isBase, $format ) =
93 PVE
:: Storage
:: parse_volname
( $storage_cfg, $volid );
95 if ( $ms ne 'rootfs' && $format ne 'subvol' && ( $scfg ->{ type
} eq 'dir' || $scfg ->{ type
} eq 'nfs' )) {
96 my $path = PVE
:: Storage
:: path
( $storage_cfg, $volid );
97 PVE
:: Tools
:: run_command
([ 'losetup' , '--find' , '--show' , $path ]);
105 push @ARGV, 'help' if ! scalar ( @ARGV );
109 if (( scalar ( @ARGV ) == 1 ) && ( $ARGV [ 0 ] eq 'printmanpod' ) ||
110 ( $ARGV [ 0 ] eq 'verifyapi' )) {
112 } elsif (( scalar ( @ARGV ) == 3 ) && ( $ARGV [ 1 ] eq 'lxc' ) && ( $ARGV [ 2 ] eq 'pre-start' )) {
113 $param ->{ name
} = $ENV { 'LXC_NAME' };
114 die "got wrong name" if $param ->{ name
} ne $ARGV [ 0 ];
116 $param ->{ path
} = $ENV { 'LXC_CONFIG_FILE' };
117 $param ->{ rootfs
} = $ENV { 'LXC_ROOTFS_PATH' };
123 my $cmddef = [ __PACKAGE__
, 'lxc-pve-prestart-hook' , [], $param ];
125 PVE
:: CLIHandler
:: handle_simple_cmd
( $cmddef, \
@ARGV, undef , $0 );
133 lxc-pve - LXC pre-start hook for Proxmox VE
141 This mount hook activate storage and volumes for pve container.
147 =include pve_copyright