cPanel & WHM no longer develops or updates EasyApache 3. We deprecated EasyApache 3 on December 31, 2018. We removed support for EasyApache 3 in cPanel & WHM version 78.
Script Hooks - EasyApache - cPanel Documentation
Page tree
Skip to end of metadata
Go to start of metadata

Overview

Script hooks execute custom-written code when system-level operations meet specified conditions.

Script hooks

To create a script hook, place a shell script inside of the /scripts/ directory, and pass any data to the script via the @ARGV variable.

The system displays a script hook's output in the command line, and also records in in the /logs file. The output contains a "before" and "after" visual separator.

You script hook must possess root:root ownership, and 755 file permissions.

ScriptDescription
/scripts/preeasyapacheThis script hook triggers when a build begins. If the build does not exit cleanly, this script hook halts the build. You can use this script to alert users of Apache's current update status, or to lock the /scripts/easyapache script so that it cannot create new builds. and prevent new builds.
/scripts/posteasyapacheThis script hook triggers at the end of a successful build. You can use this script hook to verify that a customization still functions, or alert a user when the Apache update process completes.
/scripts/before_apache_makeThis script hook runs before the make step of Apache runs.
/scripts/after_apache_make_installThis script hook runs after the make and install steps of an Apache run. Use this script hook to launch the apxs tool, which includes other Apache modules in the Apache build.
/scripts/before_httpd_restart_testsThis script hook triggers before EasyApache confirms that the httpd daemon can restart.
/scripts/after_httpd_restart_testsThis script hook triggers after EasyApache confirms that the httpd daemon can restart.

To run EasyApache without script hooks via the command line, execute the scripts/easyapache --skip-hooks script.

For information about how to run EasyApache without script hooks within WHM, read our EasyApache Profile Stage documentation.

Force a failure

You can force a failure with a script that does not exit cleanly. For example, you can configure the /scripts/preeasyapache script to prevent an EasyApache build creation if a particular condition does not exist in the system.

The following is a /scripts/preeasyapache Perl script deliberately prevents an EasyApache build creation.

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

Script hook arguments

The system passes the following arguments into ever script hook in the order that the table below lists:

ArgumentDescriptionExample
ea_version

The version of EasyApache that you currently use.

 

3.20
ea_revision

Your EasyApache version's revision number.

Note:

This value does not always appear as an integer.

4
apache

The version of Apache that the script builds.

Notes:

  • An empty string indicates that the script does not know the version of Apache.
  • A value of 0 indicates that the script will not build Apache.
  • A 2-part version string indicates that an Apache build does not exist.
  • A 3-part version string indicates that an Apache build already exists.

3.30
php_csv

A comma-separated string of which PHP versions that the script creates.

Notes:

  • An empty string indicates that script does not know the version of PHP in the Apache build.
  • A value of 0 means that the script will not install PHP.
5.3,5.4,5.6
@hook_args
Any of the --hook-args values in the order that you specified them.3.20, 4, 3.30, 5.3,5.4,5.6

The following example demonstrates how to use these arguments:

#!/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

The ea3_params_yaml variable is a script hook's environmental variable. This variable contains a YAML data structure of parameters that is sent to EasyApache.

You can use the --hook-args flag to pass custom data to script hooks, which also avoid sconflicts with any flags that the Cpanel::Easy framework uses. For example:

#!/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); }