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

internetfab

Well-Known Member
PartnerNOC
Feb 20, 2003
336
0
166
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_encode( describe() );
    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'
                 );
}    
?>
 

internetfab

Well-Known Member
PartnerNOC
Feb 20, 2003
336
0
166
Gothenburg, Sweden
cPanel Access Level
DataCenter Provider
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>
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
 

cPanelKenneth

cPanel Development
Staff member
Apr 7, 2006
4,608
77
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