Skip to main content

Adding pkgAcct Hook with varying exit codes

Comments

6 comments

  • cPanelKenneth
    According to the documentation ([url=http://docs.cpanel.net/twiki/bin/vief/SoftwareDevelopmentKit/StdHooksGettingStarted#Output%20returned%20by%20the%20hook%20acti]Getting Started) the Hook system interprets return values as follows: A value of 1 indicates that the hook action code performed successfully, while a value of 0 indicates that the hook action code failed.
    Per that, your abort function needs to return 0 to prevent further execution.
    0
  • KD0IGO
    Kenneth, I've tried to test this, but so far, this still is not succeeding. My code: #!/usr/bin/env ruby # def return_number(code) return code end return_number 0 exit 0;
    No matter what, that script returns an exit code of 0. root@pstueck-passenger [/usr/local/bin/hooks]# ./returnZero root@pstueck-passenger [/usr/local//bin/hooks]# echo $? 0
    I've added this hook to WHM for PkgAcct. However, I run PkgAcct from the command line, and this is still able to run.
    0
  • KostonConsulting
    This code should ensure the OS gets a 0 exit status: Signal.trap('EXIT') { exit 0 }
    However, I'm not sure if cPanel is actually looking at an exit code as much as it's looking a STDOUT. Try just printing 0 to STDOUT at the end of the script.
    0
  • KD0IGO
    [quote="KostonConsulting, post: 1459551">However, I'm not sure if cPanel is actually looking at an exit code as much as it's looking a STDOUT. Try just printing 0 to STDOUT at the end of the script.
    Printing 0 to STDOUT worked great. Thanks!
    0
  • KD0IGO
    Another question that I have regarding this. I'm trying to add an option to "Override" the hook, so that even with the hook running and printing "0" to STDOUT, the pkgAcct function will still continue. I have found: --allow-override Causes the script to use instructions in /var/cpanel/lib/Whostmgr/Pkgacct/pkgacct, if any are present. But, I'm unable to find any other documentation on how that needs to be formatted, what it needs to do, etc. It appears that any other arguments passed to pkgacct do not get passed along within the hash. I'm wanting to add a "--force" option for example that will allow the pkgAcct call proceed.
    0
  • KostonConsulting
    [quote="KD0IGO, post: 1468691">Another question that I have regarding this. I'm trying to add an option to "Override" the hook, so that even with the hook running and printing "0" to STDOUT, the pkgAcct function will still continue. I have found: --allow-override Causes the script to use instructions in /var/cpanel/lib/Whostmgr/Pkgacct/pkgacct, if any are present. But, I'm unable to find any other documentation on how that needs to be formatted, what it needs to do, etc. It appears that any other arguments passed to pkgacct do not get passed along within the hash. I'm wanting to add a "--force" option for example that will allow the pkgAcct call proceed.
    I'm not sure if I follow. Are you looking to pass an additional flag to /scripts/pkgacct that would then be passed to your script to allow it to continue even if there are errors? If so, I don't believe this to be possible as cpsrvd determines which data gets passed to each hook and it would likely be a security issue if you could change this. Perhaps you should instead build a development mode into your hook that checks for the existence of a debug file? For example, have the hook check for /var/cpanel/hook_debug_mode and if that file is present, it should always print 1. In addition, you could add some debug code to print additional information about the errors to a log file or /usr/local/cpanel/logs/error_log (be careful as that's a shared log file). Psuedo-code: if( -f '/var/cpanel/hook_debug_mode' ){ #open error log file handle print ERRORHANDLE "Error: example error\n"; print "1"; exit; }
    0

Please sign in to leave a comment.