cPanelTJ

Product Owner
Staff member
Jan 29, 2019
97
49
93
Houston, TX
cPanel Access Level
Root Administrator
Twitter
Using the manage_hooks utility to list my hooks, this hook appears as:


Code:
# /usr/local/cpanel/bin/manage_hooks list
...
...
Whostmgr:
        Accounts::Create:
                stage: post
                id: c19ec9d1-7b3b-40c7-b2a3-53d00ea83eb5
                hook: /usr/share/cloudlinux/hooks/cpanel/postwwwacct
                exectype: script
                weight: 200
                escalateprivs: 0
                --
                exectype: module
                weight: 300
                stage: post
                id: 58d006ef-4747-4a45-9b01-6d6503b0829c
                hook: ResellerTest::actions
...
...
 

snewton

Active Member
Aug 4, 2015
41
9
58
Redford, MI
cPanel Access Level
Root Administrator
Thanks @cPanelTJ!

I tried this code with the current registered hook and initially it didn't work, which had me shaking my head.

So I started over from scratch and found that I was registering the hook incorrectly.

After registering the hook correctly, your code as well as the code I was previously trying to use worked for the event "Accounts::Create" with no issues.

So now I want to use the same code so when an account is modified it will also do the same thing.

I tried it with the events "Accounts::Modify" and "Accounts::change_package", but the code doesn't seem to run for either.

What event do you recommend using so when a resellers plan/package is modified, the code will run?

Thanks!
 

cPanelTJ

Product Owner
Staff member
Jan 29, 2019
97
49
93
Houston, TX
cPanel Access Level
Root Administrator
Twitter
Thanks @cPanelTJ!

I tried this code with the current registered hook and initially it didn't work, which had me shaking my head.

So I started over from scratch and found that I was registering the hook incorrectly.

After registering the hook correctly, your code as well as the code I was previously trying to use worked for the event "Accounts::Create" with no issues.

So now I want to use the same code so when an account is modified it will also do the same thing.

I tried it with the events "Accounts::Modify" and "Accounts::change_package", but the code doesn't seem to run for either.

What event do you recommend using so when a resellers plan/package is modified, the code will run?

Thanks!
How did you set up your code to check for these additional events? Here is an example from our documentation that shows how to trigger off of multiple events within a single hook module: Tutorial - Create a Standardized Hook · cPanel & WHM Developer Portal

One thing to keep in mind: Anytime you change contents within the describe() method, you need to re-register your hook.
 

snewton

Active Member
Aug 4, 2015
41
9
58
Redford, MI
cPanel Access Level
Root Administrator
I figured it out.

For the additional hook for when accounts are modified, I needed to use "Accounts::change_package" for the event and then update the code to:

Code:
    my $plan = $data->{'new_pkg'};
Both create and modify work as intended, but I do see an error when an account is created and/or modified.

This is the code I am currently using for when accounts are modified:

Code:
#!/usr/local/cpanel/3rdparty/bin/perl

package ResellerLimitsModify;

use strict;
use warnings;

sub describe {
    my $hook = {
        'category' => 'Whostmgr',
        'event' => 'Accounts::change_package',
        'stage' => 'post',
        'hook' => 'ResellerLimitsModify::actions',
        'exectype' => 'module',
    };
    return $hook;
}

sub actions {

    my ( $context, $data ) = @_;
    my $user = $data->{'user'};
    my $plan = $data->{'new_pkg'};

if ( $plan eq 'Reseller Plan 1' ) {
    system`lvectl set-reseller $user --speed='100%' --pmem=3G --nproc=200 --maxEntryProcs=100 --iops=5024 --io=102400`;
} elsif ( $plan eq 'Reseller Plan 2' ) {
    system`lvectl set-reseller $user --speed='150%' --pmem=5G --nproc=200 --maxEntryProcs=150 --iops=7024 --io=256000`;
} elsif ( $plan eq 'Reseller Plan 3' ) {
    system`lvectl set-reseller $user --speed='200%' --pmem=6G --nproc=275 --maxEntryProcs=250 --iops=10024 --io=358400`;
} elsif ( $plan eq 'Reseller Plan 4 ' ) {
    system`lvectl set-reseller $user --speed='250%' --pmem=4G --nproc=300 --maxEntryProcs=200 --iops=10024 --io=204800`;
} elsif ( $plan eq 'Reseller Plan 5' ) {
    system`lvectl set-reseller $user --speed='450% --pmem=6G --nproc=425 --maxEntryProcs=400 --iops=20024 --io=460800`;
} elsif ( $plan eq 'Reseller Plan 6') {
    system`lvectl set-reseller $user --speed='550%' --pmem=8G --nproc=625 --maxEntryProcs=600 --iops=25024 --io=614400`;
} else {
   # Do nothing
}


}

1;
The above code works but during account modification, it gives the error:

A warning occurred while processing this directive.

With the following error output:

Code:
Can't exec "": No such file or directory at /usr/local/cpanel/ResellerLimitsModify.pm line 34.
 at /usr/local/cpanel/ResellerLimitsModify.pm line 25.
Line 34 is:

Code:
    system`lvectl set-reseller $user --speed="450%" --pmem=6G --nproc=425 --maxEntryProcs=400 --iops=20024 --io=460800`;
It doesn't matter which package I change to, the error output line is whichever I choose.

The code from that line runs successfully though and I can't understand what could be causing the error:

Code:
Can't exec ""
 

newjustice

Registered
Aug 18, 2011
3
1
53
The code from that line runs successfully though and I can't understand what could be causing the error:

Code:
Can't exec ""
Hi,

Have you found a solution for the Can't exec error?

I created a hook with the example provided by @cPanelTJ and I get the can't exec error for the file /usr/local/cpanel/test.txt, and the file exists and the output from the hook is executed.

Perl:
#!/usr/local/cpanel/3rdparty/bin/perl


package PMGAddDomAndTransport;

use strict;
use warnings;

sub describe {
    my $hook = {
        'category' => 'Whostmgr',
        'event' => 'Accounts::Create',
        'stage' => 'post',
        'hook' => 'PMGAddDomAndTransport::actions',
        'exectype' => 'module',
    };
    return $hook;
}

sub actions {

    my ( $context, $data ) = @_;
    my $user = $data->{'user'};
    my $plan = $data->{'plan'};
my $domain = $data->{'domain'};

if ( $plan eq 'Package with Spaces' ) {
    system`echo "FROM ULC Test succeeded for User: $user and domain: $domain" >> /usr/local/cpanel/test.txt`;
 } else {
    system`echo "Test failed FROM ULC $domain" >> /usr/local/cpanel/test.txt`;
 }

}

1;
Code:
[2021-11-18 21:42:48 +0200] warn [Internal Warning while parsing [stdin] 20353] Can't exec "": No such file or directory at /var/cpanel/perl5/lib/PMGAddDomAndTransport.pm line 29.
 at /var/cpanel/perl5/lib/PMGAddDomAndTransport.pm line 29.
        PMGAddDomAndTransport::actions(HASH(0x58fe688), HASH(0x1ed0360)) called at /usr/local/cpanel/Cpanel/Hooks.pm line 536
        eval {...} called at /usr/local/cpanel/Cpanel/Hooks.pm line 534
        Cpanel::Hooks::_exec_module("main", HASH(0x5289a48), HASH(0x58fe688), HASH(0x1ed0360)) called at /usr/local/cpanel/Cpanel/Hooks.pm line 354
        Cpanel::Hooks::_exec_hook("main", HASH(0x5289a48), HASH(0x58fe688), HASH(0x1ed0360)) called at /usr/local/cpanel/Cpanel/Hooks.pm line 273
        eval {...} called at /usr/local/cpanel/Cpanel/Hooks.pm line 268
        Cpanel::Hooks::hook(HASH(0x58fe688), HASH(0x1ed0360)) called at /usr/local/cpanel/Whostmgr/Accounts/Create.pm line 2743
        Whostmgr::Accounts::Create::_execute_post_creation_hooks(HASH(0x4586458), HASH(0x1ed0360)) called at /usr/local/cpanel/Whostmgr/Accounts/Create.pm line 461
        Whostmgr::Accounts::Create::_wwwacct(__CPANEL_HIDDEN__, 0, __CPANEL_HIDDEN__, undef, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, ...) called at /usr/local/cpanel/Whostmgr/Accounts/Create.pm line 3336
        Whostmgr::Accounts::Create::__createaccount(__CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, 0, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, ...) called at /usr/local/cpanel/Whostmgr/Accounts/Create.pm line 3471
        Whostmgr::Accounts::Create::_createaccount(__CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, 0, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, ...) called at whostmgr/bin/whostmgr5.pl line 791
        main::wwwacct("wwwacct") called at /usr/local/cpanel/Whostmgr/Dispatch.pm line 366
        Whostmgr::Dispatch::_do_call("wwwacct", HASH(0x3d6ea90), HASH(0x3d72b48)) called at /usr/local/cpanel/Whostmgr/Dispatch.pm line 178
        Whostmgr::Dispatch::dispatch("wwwacct", 1, ARRAY(0x3d44998), HASH(0x3d72b48)) called at whostmgr/bin/whostmgr5.pl line 264
Thanks.
 
  • Like
Reactions: cPanelAnthony