cPanel® Blog

cPanel Auto Provisioning through Kickstart

In my last post I talked about how to create the CentOS/cPanel installer ISO.  This information is good, but what if you want to do something more?  What if you wanted to pre-configure cPanel? What if you wanted cPanel to automatically use a certain EasyApache profile?

You can easily accomplish this in a way that can be used with any kickstart-based deployment method, not just the ISO image method.

Kickstart works by passing a kickstart file to anaconda (the Red Hat® installer application).  This application specifies certain installation options, such as what packages need to be installed, the partitioning layout, etc. Red Hat has documentation on this here and CentOS has a nice “Tips and Tricks” guide here.

These articles cover how to handle the OS configuration aspect of kickstart. But what about the cPanel configuration?

Details
The way that cPanel installs inside of the cpanel-ks.cfg file that we provide is by executing a script on first boot if /var/cpanel does not exist:

cat <<EOM >> /etc/rc.local
if [ ! -d "/var/cpanel"  ]; then
nohup /home/cpinst/CDinstaller.sh & > /dev/null
fi
EOM

We will make most of our changes to CDinstaller.sh, where it is embedded inside cpanel-ks.cfg after %post. This way, we can ensure that installation actions are performed at the correct point (e.g. before or after the cPanel installation).

Here is a copy of the CDInstaller.sh file that appears within cpanel-ks.cfg, with comments to show where you should add the pre- and post-installation actions.
cat <<EOM >> /home/cpinst/CDinstaller.sh
#!/bin/bash
function messenger {
echo $1 >> /dev/console
wall $1
echo $1 >> /var/log/cpanel-install-autoinstaller.log
}
if ! nc -z httpupdate.cpanel.net 80 -w 10 > /dev/null; then
messenger "Could not reach httpupdate.cpanel.net, aborting installation. Please resolve this issue and reboot to proceed with installation."
exit
fi
touch /var/log/cpanel-install-thread0.log
touch /var/log/cpanel-install-thread1.log
messenger "Starting CentOS system update"
yum update -y
messenger "Finished CentOS system update, starting cPanel installation"
cd /home/cpinst
## PRE INSTALLATION SECTION
wget http://httpupdate.cpanel.net/latest
mkdir -p /usr/local/cpanel/logs
CPANEL_LOGGER_FILE:/usr/local/cpanel/logs/cpanel-install-autoinstaller.log
sh latest
if [ -d "/var/cpanel" ]; then
mv /etc/motd.orig /etc/motd
messenger "cPanel installation Complete"
fi
## POST INSTALLATION SECTION
EOM

Within the CDinstaller.sh file, we have an additional function that we should note:  “messenger”. This function is used for providing status updates to the shell and logs. Anytime an action is added, the messenger function should be used to send a status update.

Setting your branch
The most basic of tasks would be to add a branch. You can easily accomplish this by echoing the string “CPANEL=$branch” to /etc/cpupdate.conf. For example, in the pre-installation section of cpanel-ks.cfg you would add:
messenger “Setting cPanel branch to stable”
echo “CPANEL=stable” > /etc/cpupdate.conf

This will make the installer automatically install cPanel’s stable branch.  Valid strings for this parameter are: edge, current, release (The default cPanel installation branch) and stable.  You can also disable automatic updates by adding “-manual” to the end of this string  (e.g. “CPANEL=stable-manual”).

Configuring cPanel
cPanel’s Tweak Settings configuration is handled by /var/cpanel/cpanel.config. This controls options such as which webmail clients are installed, which nameserver and SMTP dameons to use, and memory limits (see: http://docs.cpanel.net/twiki/bin/view/AllDocumentation/InstallationGuide/AdvancedOptions for more information).  To control these settings before installing cPanel, you will need to create the /root/cpanel_profile/cpanel.config file.  To view available options, you can look at /var/cpanel/cpanel.config on an existing system.

There are two logical ways to populate the cpanel.config file:

One method of setting options within cpanel.config would be to simply echo values into the file:
mkdir -p /root/cpanel_profile/
messenger “Setting cPanel to use Courier”
echo “mailserver=courier” >> /root/cpanel_profile/cpanel.config

cpanel.config is portable from system to system as it contains no-system specific information.  This means that you can generate cpanel.config on anexisting cPanel server, host it on an accessible web server, and use it with CDinstaller.sh:
messenger “Downloading cPanel Profile”
mkdir -p /root/cpanel_profile/
wget -O /root/cpanel_profile/cpanel.config http://somehost/cpanel.config

Warning:  It is important to note that the installer is not normally tested with all possible permutations of cpanel.config.  Please be aware of this fact and test your configuration before production deployment.

EasyApache Profiles
One thing that I find annoying about provisioning a cPanel server is having to recompile Apache/PHP after cPanel has been installed.  Luckily, the installer can provide an EasyApache profile so that Apache/PHP/etc are built with your desired settings when cPanel is installed.  The first step to doing this is that you need to generate an EA3 profile on an existing cPanel server:

  1. Log in to WHM.
  2. Click on EasyApache (Apache Update).
  3. Click Start Customizing Based on Profile.
  4. Go through the steps until you reach step 5, and click on Exhaustive options list (at the bottom).
  5. At the very bottom of the exhaustive options list, you will see Save Selections as Custom Profile. Fill out this information, then click on Save Only (DO NOT BUILD).
  6. Click on Go back to profile screen.
  7. Click on More Info next to the profile you created.
  8. Click on Download profile.

This will provide you with an EasyApache profile you can use during the installation of your system.  At this point in the pre-installation section of CDinstaller.sh, you can use wget to download the /etc/cp_easyapache_profile.yaml to your system.

messenger “Downloading EA3 Profile”
wget -O /etc/cp_easyapache_profile.yaml http://somehost/someprofile.yaml

Installation of Third-Party Software
I know that a lot of our customers use third-party software (this blog *is* about product integration, isn’t it?).  When setting up a server, it would be handy to have some software automatically installed.  For example, you can automatically have CSF (ConfigServer’s excellent free firewall for cPanel/WHM) installed by specifying a few extra steps in the %post-installation section:
messenger “Installing CSF”
wget http://www.configserver.com/free/csf.tgz
tar vzxf csf.tgz
cd csf
./install.cpanel.sh
perl -i -pe 's/T
ESTING = "1"/TESTING = "0"/' /etc/csf/csf.conf
csf -r
cd -

This will install CSF and disable testing mode automatically (which should be fine on a fresh server).

That covers all of the points we will discuss regarding kickstart provisioning in this blog post.  In the next post of this series, I will discuss how to automate the Getting Started Wizard in WHM.

cPanel

The web hosting industry's most reliable, intuitive control panel since 1997. With our first-class support and rich feature set, it's easy to see why our customers and partners make cPanel & WHM their hosting platform of choice. For more information, visit cPanel.com.