+};
+
+sub run_cli {
+ my ($class, $pwcallback, $podfn, $preparefunc) = @_;
+
+ # Note: "depreciated function run_cli - use run_cli_handler instead";
+
+ die "password callback is no longer supported" if $pwcallback;
+
+ run_cli_handler($class, podfn => $podfn, prepare => $preparefunc);
+}
+
+sub run_cli_handler {
+ my ($class, %params) = @_;
+
+ $cli_handler_class = $class;
+
+ $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
+
+ foreach my $key (keys %params) {
+ next if $key eq 'podfn';
+ next if $key eq 'prepare';
+ next if $key eq 'no_init'; # used by lxc hooks
+ die "unknown parameter '$key'";
+ }
+
+ my $podfn = $params{podfn};
+ my $preparefunc = $params{prepare};
+ my $no_init = $params{no_init};
+
+ my $pwcallback = $class->can('read_password');
+
+ $exename = &$get_exe_name($class);
+
+ initlog($exename);
+
+ if ($class !~ m/^PVE::Service::/) {
+ die "please run as root\n" if $> != 0;
+
+ PVE::INotify::inotify_init() if !$no_init;
+
+ my $rpcenv = PVE::RPCEnvironment->init('cli');
+ $rpcenv->init_request() if !$no_init;
+ $rpcenv->set_language($ENV{LANG});
+ $rpcenv->set_user('root@pam');
+ }
+
+ no strict 'refs';
+ my $def = ${"${class}::cmddef"};
+
+ if (ref($def) eq 'ARRAY') {
+ &$handle_simple_cmd($def, \@ARGV, $pwcallback, $podfn, $preparefunc);
+ } else {
+ $cmddef = $def;
+ my $cmd = shift @ARGV;
+ &$handle_cmd($cmddef, $exename, $cmd, \@ARGV, $pwcallback, $podfn, $preparefunc);
+ }
+
+ exit 0;