#!/bin/bash

# Shut down cPanel/TailWatch/ChkServd/Apache/Exim, just like a final sync.
/usr/local/cpanel/bin/tailwatchd --disable=Cpanel::TailWatch::ChkServd &> /dev/null
if [ -e /usr/bin/systemctl ]; then
	systemctl stop httpd.service &> /dev/null
	systemctl stop exim.service &> /dev/null
else
	/etc/init.d/httpd stop &> /dev/null
	/etc/init.d/exim stop &> /dev/null
fi

# Pulling in the maintenance binary and running it in the background.
wget -q -O /root/maintenance http://files.sysres.liquidweb.com/maintenance/maintenance
chmod 700 /root/maintenance
/root/maintenance &

# trap that pid for later
maint_pid="$!"

# Here's where the final sync would go, if we were doing a final sync.
echo "Here's were we would do the final sync."
sleep 3
echo "Assuming we actually had a final sync to do."
sleep 3
echo "Seeing as we don't, we'll just sleep for a few minutes so you can check out the maintenance page."
sleep 180

# Take down the maintenance page and restart services.
kill $maint_pid

/usr/local/cpanel/bin/tailwatchd --enable=Cpanel::TailWatch::ChkServd &> /dev/null
/scripts/restartsrv_tailwatchd
if [ -e /usr/bin/systemctl ]; then
	systemctl start httpd.service &> /dev/null
	systemctl start exim.service &> /dev/null
else
	/etc/init.d/httpd start &> /dev/null
	/etc/init.d/exim start &> /dev/null
fi
