How do I run command or script in a Container from Parallels Business Automation Container (former HSPcomplete VE)?

Article ID: 3987 
Last Review: Oct,6 2008
Author: Rozet Irina APPLIES TO:
  • HSPcomplete 3.3.x

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


Subscription for this article changesSubscription for this article changes

Please provide feedback on this article

Did this article help you solve your issue?
Yes
No
Partially
I do not know yet
 
Strongly Agree   Strongly Disagree
  9 8 7 6 5 4 3 2 1
The article is easy to understand
The article is accurate
Additional Comments:
*Please provide us with your email address in case we need to contact you.
* - required fields