Setting Cron Interval

Configure Crons for Production

When CoffeeCP is installed it adds two cron jobs to your root crontab at /var/spool/cron/root:


			* * * * * /usr/coffeecp/scripts/coffeecp_build_json.sh   > /dev/null 2>&1
* * * * * /usr/coffeecp/scripts/config-helper.sh > /dev/null 2>&1

To facilitate getting the service started and all required files created, the crons are set to run once per minute.

Once you have verified the installation by creating a user account, you should change these to a larger interval.

The following is recommended for production:


			0 * * * * /usr/coffeecp/scripts/coffeecp_build_json.sh   > /dev/null 2>&1
0/15 * * * * /usr/coffeecp/scripts/config-helper.sh > /dev/null 2>&1

The above is only a recommendation and can be adjusted to suit your requirements.

About the Cron Jobs

coffeecp_build_json.sh

The coffeecp_build_json.sh bash file is used to update any changes to available application servers as well as JDKs.

It can be run at any interval you wish to as well as on-demand.

The script can also be modified if you wish to do so, but care should be taken.

 

 

			
			#!/bin/bash

COFFEECP_HOME='/usr/coffeecp'
FINAL_JSON='{\n'

function build_servers_list(){

	FINAL_JSON+='"servers": [\n'
	DELIMITER='';

	for f in $(ls "${COFFEECP_HOME}/appfiles"); do
		type=${f%%-*}
		case $type in
			apache)
				version=$(echo ${f} | sed 's/.*apache-tomcat-\([0-9\.]\+\).zip$/\1/')
				FINAL_JSON+="${DELIMITER}{ \"version\": \"${version}\", \"name\": \"Tomcat\", \"type\": 1, \"folder_name\": \"apache-tomcat-${version:0:1}x\", \"path\": \"${COFFEECP_HOME}/appfiles/apache-tomcat-${version}.zip\"}"
				;;
			wildfly)
				version=$(echo ${f} | sed 's/.*wildfly-\([a-zA-Z0-9\.]\+\).zip$/\1/')
				FINAL_JSON+="${DELIMITER}{ \"version\": \"${version}\", \"name\": \"WildFly\", \"type\": 2, \"folder_name\": \"wildfly-${version:0:2}x\", \"path\": \"${COFFEECP_HOME}/appfiles/wildfly-${version}.zip\"}"
				;;
			glassfish)
				version=$(echo ${f} | sed 's/.*glassfish-\([0-9\.]\+\).zip$/\1/')
				FINAL_JSON+="${DELIMITER}{ \"version\": \"${version}\", \"name\": \"GlassFish\", \"type\": 3, \"folder_name\": \"glassfish${version:0:1}\", \"path\": \"${COFFEECP_HOME}/appfiles/glassfish-${version}.zip\"}"
				;;
			*)
				echo "Error: Unknown file type for ${f}"
				;;
		esac
		DELIMITER=','
	done

	FINAL_JSON+=' ]\n'
}

function build_jdk_list(){
	FINAL_JSON+=',"JDK": ['

	DELIMITER='';
	for f in $(ls "/usr/java"); do
		version=$(echo ${f} | sed 's/.*jdk1\.-\([a-zA-Z0-9\._]\+\)$/\1/')
		FINAL_JSON+="${DELIMITER}{ \"version\": \"${version}\", \"name\": \"JDK\",\"path\": \"/usr/java/${f}\"}"
		DELIMITER=','
	done

	FINAL_JSON+=']'
	return 0;
}


build_servers_list;
build_jdk_list;

FINAL_JSON+='\n}'

echo -e "${FINAL_JSON}" > /usr/coffeecp/json/coffeecp_server.json

 

config-helper.sh

The config-helper.sh is used soley to create domain mappings.

In general, users will only map an application once, although they might update with various path maps and exclusions.

As mapping is an infrequent activity, you can also opt to disable the cron and run it only on a ticket request basis.

 


			#!/bin/bash

FLAG_RELOAD=0
for user in $(ls /home); do
	if [ -f "/home/${user}/reload.txt" ]; then
		USER=$(cut -f1 -d' ' /home/${user}/reload.txt)
		DOMAIN=$(cut -f2 -d' ' /home/${user}/reload.txt)
		php /usr/coffeecp/paths/index.php ${USER} ${DOMAIN}

		FLAG_RELOAD=1
		rm -f /home/${user}/reload.txt
	fi

	if [ -f "/home/${user}/mapping.txt" ]; then
		USER=$(cut -f1 -d' ' /home/${user}/mapping.txt)
		DOMAIN=$(cut -f2 -d' ' /home/${user}/mapping.txt)
		TYPE=$(cut -f3 -d' ' /home/${user}/mapping.txt)
		php /usr/coffeecp/paths/mapping.php ${USER} ${DOMAIN} ${TYPE}

		FLAG_RELOAD=1
		rm -f /home/${user}/mapping.txt
	fi
done

if [ ${FLAG_RELOAD} = 1 ]; then
	/usr/sbin/httpd -k graceful
fi

			
			

Up Next: Create User Accounts

Enabling cPanel Users for CoffeeCP