Cpanel Development: Using preeasyapache and posteasyapache

Community support for Plesk, CPanel, WebMin and others with insight from two of the founders of Plesk. Ask for help here! No question is too simple or complicated. :-)
scott
Atomicorp Staff - Site Admin
Atomicorp Staff - Site Admin
Posts: 8355
Joined: Wed Dec 31, 1969 8:00 pm
Location: earth
Contact:

Cpanel Development: Using preeasyapache and posteasyapache

Unread post by scott »

Background:
Easyapache is the component in cpanel that is responsible for downloading and compiling apache and its requisite dependencies. It includes the ability to add events to run before and after easyapache runs for 3rd parties to insert actions into or after the build and installation process.

General notes:
easyapache does not return error codes to the command line, it does however use some basic internal logic to validate the pre & post events. This is problematic for automation without human interaction.

The events:
/scripts/preeasyapache - this is invoked by /scripts/easyapache prior to starting the build process. It can be an executable of any type. This is problematic if 3rd party vendors use different languages in these events, like perl.
/scripts/posteasyapache - this is invoked by /scripts/easyapache after completing the build process. It can be an executable of any type.

Recommendation:
Both Atomicorp and Cloudlinux rely on the pre & post events in order to install our software. In order to provide a consistent experience across software, Cloudlinux developed the following method to use this part of the API, which we have also adopted.

1) pre & post easyapache are to be used as shell scripts only
2) these events invoke other scripts or executables that can be in any language your application needs.

The following is an example of /scripts/posteasyapache using this method:
#!/bin/sh

/var/asl/data/templates/template-cpanel-apache-hook #ASL_HOOK
Note that the Atomicorp event is now referenced from inside /scripts/posteasyapache, and the final line includes a tag: ASL_HOOK (more on this in a sec). A 3rd party change to posteasyapache would look like the following:
#!/bin/sh

/var/asl/data/templates/template-cpanel-apache-hook #ASL_HOOK
/path/to/my/script #MY_SCRIPT_TAG
This allows any number of 3rd party vendors to co-exist using the easyapache pre & post events. This simple shell script example shows how a 3rd party vendor can write an installer, or an event to verify that their script is in place in /scripts/posteasyapache:

Code: Select all

if [ -f /scripts/posteasyapache ]; then
			if ! egrep "ASL_HOOK" /scripts/posteasyapache ; then
				echo "/var/asl/data/templates/template-cpanel-apache-hook #ASL_HOOK" >> /scripts/posteasyapache
			fi
else 
			install -m0755 /var/asl/data/templates/template-cpanel-posteasyapache /scripts/posteasyapache
fi
The first event is to detect if /scripts/easyapache exists, if it does we then perform a simple grep event to look for our tag (ASL_HOOK) exists. If it does not, we append our event to posteasyapache. The final condition installs a default posteasyapache script if it otherwise does not exist.

In conclusion:
1) When in doubt ask! Its in all our best interests to use a method that works across platforms
2) use shell scripting as the base language in pre & post easyapache events
3) return errror values back to the pre & posteasyapache script, it might not use them but the next vendor in the chain could
4) Reference your event from the pre & post scripts, don't overwrite it
5) And I'll repeat it, when in doubt ask!
Post Reply