Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Having a go at the standardized hooks system - script hook not executable?

Discussion in 'cPanel Developers' started by internetfab, Aug 29, 2012.

  1. internetfab

    internetfab Well-Known Member
    PartnerNOC

    Joined:
    Feb 20, 2003
    Messages:
    336
    Likes Received:
    0
    Trophy Points:
    166
    Location:
    Gothenburg, Sweden
    cPanel Access Level:
    DataCenter Provider
    Testing out the new hooks system but am running into some issues.
    Following the example here on Managing a script:
    Standardized Hooks Management Interface

    The output of the following gives:
    /usr/local/cpanel/bin/manage_hooks add script /usr/local/oder/su/hooks/system/postupcp.php
    The provided script hook is not executable
    There was a failure adding a hook, removing all hooks contained with in. Please contact the maintainer of this hook for assistance.

    PHP:
    #!/usr/bin/php -q
    <?php
    // file - /usr/local/oder/su/hooks/system/postupcp.php

    // Any switches passed to this script
    $switches = (count($argv) > 1) ? $argv : array();

    if (
    in_array('--describe'$switches)) {
        echo 
    json_encodedescribe() );
        exit;
    } elseif (
    in_array('--fixfiles'$switches)) {
        list(
    $status$msg) = fixfiles();
        echo 
    "$status $msg";
        exit;  
    } else {
        echo 
    '0 postupcp.php needs a valid switch';
        exit(
    1);
    }

    function 
    describe() {
        
    $my_fixfiles = array(
            
    'category' => 'System',
            
    'event'    => 'System::upcp',
            
    'stage'    => 'post',
            
    'hook'     => '/usr/local/oder/su/hooks/system/postupcp.php --fixfiles',
            
    'exectype' => 'script',
        );
        return array(
    $my_fixfiles);
    }

    function 
    fixfiles() {
        
    shell_exec('
                   chgrp bb /root/test.txt
                   '
    );
        
    shell_exec('
                   chmod g+r /root/test.txt
                   '
    );
        return array(
                     
    'Success',
                     
    'File /root/test.txt should be fixed'
                     
    );
    }    
    ?>
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. charsleysa

    charsleysa Active Member

    Joined:
    Jul 18, 2011
    Messages:
    41
    Likes Received:
    0
    Trophy Points:
    56
    Location:
    Palmerston North, New Zealand
    cPanel Access Level:
    Root Administrator
    Re: Having a go at the standardized hooks system - script hook not executab

    You need to change the permissions on the file to executable, to do that I think it's a simple shell command like so:
    chmod a+x <filename>
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. internetfab

    internetfab Well-Known Member
    PartnerNOC

    Joined:
    Feb 20, 2003
    Messages:
    336
    Likes Received:
    0
    Trophy Points:
    166
    Location:
    Gothenburg, Sweden
    cPanel Access Level:
    DataCenter Provider
    Re: Having a go at the standardized hooks system - script hook not executab

    That has of course already been tested ;)

    The script works perfectly being called from CLI like this:

    /usr/local/oder/su/hooks/system/postupcp.php --fixfiles
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. cPanelKenneth

    cPanelKenneth cPanel Development
    Staff Member

    Joined:
    Apr 7, 2006
    Messages:
    4,563
    Likes Received:
    43
    Trophy Points:
    308
    cPanel Access Level:
    Root Administrator
    Re: Having a go at the standardized hooks system - script hook not executab

    What is the full command line you are using?

    For example, using your script on a test system, I used the following to add the script to the hook system:

    Code:
    # /usr/local/cpanel/bin/manage_hooks add script /usr/local/oder/su/hooks/system/postupcp.php --manual --category System --event upcp --stage post
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice