Documentation Home> EasyApache3>DeveloperResourcesWebHome? EditAttach

EasyApache Hook Scripts

Introduction

Below is a list of hook scripts easyapache calls if they exist and are executable.

Their output is sent to the screen and the log, and has a "before" and "after" alert to visually separate it from the rest of the output.

Unless otherwise noted, the exit value is ignored.

Hook scripts:

  • /scripts/preeasyapache — Use this at the very beginning of a build. If it does not exit cleanly, will halt the build (i.e., exit(1);). Potential uses: to lock easyapache to keep it from building; to alert users Apache is currently being updated.
  • /scripts/posteasyapache — Use this at the very end of a successful build. Potential uses: to verify some customization is still working properly and alert someone if it is not; to alert users when the Apache update is complete.

The following scripts use "before" or "after" in their names, instead of "pre" or "post," to help indicate they relate to specific parts instead of the entire script:

  • /scripts/before_apache_make
  • /scripts/after_apache_make_install
    • PICK Hint: This is where you should use the apxs tool to include other Apache modules.
  • /scripts/before_httpd_restart_tests
  • /scripts/after_httpd_restart_tests

Use --skip-hooks to build without running any hooks (or the WHM equivalent found in EasyApache's Help section).

Triggering a Failure

When checking a hook script's exit status, a failure can be triggered by creating a script that does not exit cleanly. For example, this idea is useful when using /scripts/preeasyapache to prevent EasyApache from building if a particular condition is not met.

Using /scripts/preeasyapache, you could prevent EasyApache from building with the following Perl script:

#!/usr/bin/perl

my $file = '/etc/disable_easyapache_builds';
if (-e $file) {
   print "The admin has disabled me via $file\n";
   exit 1;
}

Hook Script Arguments

Every hook script will have the following arguments passed to it in this order:

  • EasyApache version — The version of EasyApache in use.
  • EasyApache revision — The revision number of the EasyApache version.
    • note Note: This value will not always be an integer.
  • Apache Version Being Built — The version of Apache being built.
    • An empty string means that it is not yet known which version of Apache is being built.
    • A value of 0 means that Apache will not be built.
    • A 2-part version string means that Apache has not been built yet.
    • A 3-part version string means that Apache has already been built.
  • PHP Versions — A comma-separated string of which PHP versions are being built.
    • An empty string means that which PHP versions are being built is not yet known.
    • A value of 0 means that PHP will not be built.
  • --hook-args values — Any of the --hook-args in the order that they were specified. (Please see The ea3_params_yaml Environment Variable below.)

#!/usr/bin/perl

my ($ea_version, $ea_revision, $apache, $php_csv, @hook_args) = @ARGV;

if ($ea_revision ne int($ea_revision)) {
    print "using a branch of some sort\n";
}

my @phps = split(/,/, $php_csv);

if( !$apache ) {
    if ( $apache == 0) {
        print "We are not building apache this run\n";
    }
    elsif ($apache eq '') {
        print "I must be /scripts/preeasyapache\n";
    }
}

The ea3_params_yaml Environment Variable

Every hook script will have an environment variable called ea3_params_yaml. This variable contains a YAML data structure of parameters that are sent to EasyApache.

You should use --hook-args to pass custom data to hook scripts. This will avoid conflicts with any flags used by the Cpanel::Easy framework.

#!/usr/bin/perl

use YAML::Syck;
my $hr = YAMl::Syck::Load( $ENV{'ea3_params_yaml'} );

if ( exists $hr->{'hook-args'} && grep( /no notify/, @{ $hr->{'hook-args'} }) ) {
    print "Skipping user notification\n";
}
else {
    print "Notifying users...\n";
    notify_users($msg);
}
Topic revision: r4 - 05 Nov 2009 - 19:38:42 - Main.JustinSchaefer
 

Copyright © cPanel 2000-2009.