cPanelTJ

Product Owner
Staff member
Jan 29, 2019
95
45
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
7
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
95
45
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
7
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 ""