Published on: March 3, 2016 by Shafeer P
Server Provisioning is one of the most routinely performed activities in Web hosting environment. cPanel is the most popular hosting control panel in the industry. Naturally there is huge demand for creation of OnApp enabled cPanel hosting servers.
It is possible to create a template for cPanel VMs and its VM instances in OnApp. However, each VM will have its own identity elements such as IP, Hostname etc. These parameters are defined in various configuration files of each cPanel and other related services. Proper functioning of each cPanel VMs depends these unique values and hence the general values specified in the template needs modification. Changing the configuration files in accordance with the requirement of each VM is obviously a tedious task.
OnApp provides great tool for such operations on VMs, named Recipe. However, due to the security layer of cPanel architecture, Recipe cannot be executed in cPanel servers by default.
We can overcome this restriction by implementing a simple tweak, as discussed below.
1. Create an empty Virtual Server for template: See
2. Install and configure the cPanel: See
3. Install required third-party optional packages required.
For example, we can install third-party packages such as Softaculous, Percona MySQL, LiteSpeed etc.
Now, let us go deeper in to the OnApp Recipe setup.
4. Prepare the OnApp recipe script
4a. Recipe prerequisties and preperations
mount -o remount exec /tmp
This mount option will be removed automatically during Recipe execution.
/bin/cp -p /etc/fstab /etc/fstab.cpanel
4b. The shell scripts
#!/bin/bash ## Script to update IP/Hostname after OnApp VM deployment. WWW_CONF=/etc/wwwacct.conf RDNS_CONF=/etc/mail_reverse_dns HTTP_CONF=/usr/local/apache/conf/httpd.conf LOG_FILE=/var/log/recipe.log :> $LOG_FILE OLD_IP= # Input the IP address of the Template server here NEW_IP=$IP_ADDRESS OLD_HOST= # Input the hostname of the Template server here NEW_HOST=$HOSTNAME echo "Old IP address: $OLD_IP" echo "New IP address: $NEW_IP" echo "Old hostname: $OLD_HOST" echo "New hostname: $NEW_HOST" if [ "$OLD_HOST" == "$NEW_HOST" ] then echo "Error: This script won't run on this server!" exit 1 fi echo -e "\nStopping cPanel and Apache..." /etc/init.d/cpanel stop &>> $LOG_FILE /etc/init.d/httpd stop &>> $LOG_FILE echo -e "Updating IP in wwwacct.conf..." replace $OLD_IP $NEW_IP -- $WWW_CONF &>> $LOG_FILE echo -e "Updating Main IP for cPanel..." /scripts/mainipcheck &>> $LOG_FILE echo -e "Updating Exim RDNS..." replace $OLD_IP $NEW_IP -- $RDNS_CONF &>> $LOG_FILE replace $OLD_HOST $NEW_HOST -- $RDNS_CONF &>> $LOG_FILE echo -e "Updating Apache configuration..." /scripts/rebuildhttpdconf &>> $LOG_FILE replace $OLD_IP $NEW_IP -- $HTTP_CONF &>> $LOG_FILE replace $OLD_HOST $NEW_HOST -- $HTTP_CONF &>> $LOG_FILE /usr/local/cpanel/bin/apache_conf_distiller --update &>> $LOG_FILE echo -e "Staring Apache..." /etc/init.d/httpd start &>> $LOG_FILE echo -e "Updating cPanel license..." /usr/local/cpanel/cpkeyclt &>> $LOG_FILE echo -e "Staring cPanel..." /etc/init.d/cpanel start &>> $LOG_FILE echo -e "Updating Hostname via WHM..." curl --insecure --user root:$ROOT_PASSWORD https://$NEW_IP:2087/scripts2/dochangehostname?hostname=$NEW_HOST &>> $LOG_FILE ## FSTAB hardening echo -e "\nHardening fstab..." mv -f /etc/fstab /etc/fstab.onapp &>> $LOG_FILE /bin/cp /etc/fstab.cpanel /etc/fstab &>> $LOG_FILE mount -a &>> $LOG_FILE mount -o remount / &>> $LOG_FILE replace "`grep mount /root/.bashrc `" "" -- /root/.bashrc &>> $LOG_FILE echo -e "\nUpdating file system quota..." /scripts/fixquotas &>> $LOG_FILE
Note: You need to enter the values for the variables OLD_HOST and OLD_IP with the IP and hostname of the Template server.
5. Create OnApp Recipe
Refer this article for creating the OnApp Recipe. In the script field, enter the following command.
Category : cPanel, Howtos, Linux