The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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:
    16
    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'
                     
    );
    }    
    ?>
     
  2. charsleysa

    charsleysa Active Member

    Joined:
    Jul 18, 2011
    Messages:
    41
    Likes Received:
    0
    Trophy Points:
    6
    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>
     
  3. internetfab

    internetfab Well-Known Member
    PartnerNOC

    Joined:
    Feb 20, 2003
    Messages:
    336
    Likes Received:
    0
    Trophy Points:
    16
    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
     
  4. cPanelKenneth

    cPanelKenneth cPanel Development
    Staff Member

    Joined:
    Apr 7, 2006
    Messages:
    4,458
    Likes Received:
    22
    Trophy Points:
    38
    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
    
     
Loading...
Similar Threads - Having standardized hooks
  1. jleckie
    Replies:
    2
    Views:
    449

Share This Page