SYMPTOMS
Sometimes it's necessary to perform a command in Container on event of Container creation or when an Application template is installed into Container. Also, sometimes provider wishes to adjust some settings in a group of Containers at once.RESOLUTION
You can run a script inside PBAS Container to perform a command in a Container registered in PBAS. Such script can be called either from command line, or set as 'run custom script' action on an event, such as events 'Container has been created', 'Application template has been installed into Container'.Here is example script which retrieves plesk admin password from a Windows Plesk container.
Script receives Container ID as first argument.
##############################
#!/usr/bin/perl
use strict;
map { delete( $ENV{ $_ } ) } keys %ENV;
use HSPC::Console;
use HSPC::MT::OM;
use HSPC::MT::VESrv;
use HSPC::MT::VESrv::Constants;
my $ve_id = $ARGV[0];
my $ve=HSPC::MT::OM->find_ve(id=>$ve_id);
die("Can't find VE #$ve_id") unless ($ve);
my $gate = HSPC::MT::VESrv->find_gate_obj(ve_obj => $ve,
gate_id => SW_VESRV_GATE_VE);
die("Can't open gate") unless ($gate);
my ($cmd_err, $cmd_out);
my $ret_code = $gate->exec(
argv => [
'C:\SWsoft\Plesk\admin\bin\plesksrvclient.exe',
'-get',
'-nogui',
],
stderr => \$cmd_err,
stdout => \$cmd_out,
);
if ($ret_code) {
print "Error: $ret_code:$cmd_err:$cmd_out\n";
}
else {
print "Result: $cmd_out\n";
}
###################################
For linux Container we also can use /bin/sh as argv, and pass a command in stdin,
which allows to perform several commands at once. Example (setting new Plesk admin password):
my $cmd = <<CMD;
export PSA_PASSWORD='NEW_PASSWORD'; /usr/local/psa/admin/sbin/ch_admin_passwd; unset PSA_PASSWORD;
CMD
my ($err, $out);
$gate->exec(
env => {'LANG', 'C'},
argv => ['/bin/sh'],
stdin => \$cmd,
stderr => \$err,
stdout => \$out
);
Keywords: HSPcomplete PBAS script Container VE command