Failover with Google Drive

Is your website often goes down, do you use free web host service or host website from home with dynamic ip, then i have come up with the solution to keep your website always online. In this howto we are going to use google drive to host our failover script.
This solution is free, major requirements is you must have third party DNS host like ZoneEdit and Google account, considering you have own domain name with admin rights.

So lets begain.

First click me, By clicking new Windows/Tab will open and will display as below

Screenshot of response after clicking link - Failover with Google Docs

Now Make a copy by Clicking “Yes, make a copy.” It will create a copy of document

Screenshot after document copied - Failover with Google Docs

Records sheet will keep record of website status, response from website and Response from DNS host, Settings sheet for entering required information for example Servers, Domain names, Alert Settings etc…
Open Settings Sheet

Screenshot of Settings page - Failover with Google Docs

NOTE : Change only Light Gray cells

In this sheet you have to enter DNS update url, In case of ZoneEdit its change as required or delete if dont want to update A records.
NOTE : if disabled Script will only monitor and alert depending upon settings, You will required to change A records manually.
Next are DNS error codes, for ZoneEdit refer, This codes are important to make script work properly.

Change username and password with yours.

Replace Servers with yours and delete rest server entries, In my case i have created sub-domains for each servers and Updated dns records manually to serve by respected servers, For example hosted by serverx, hosted by servery, so on.
Now create a webpage with some contents (prefer numeric output) and upload it to all respected servers, in my case i created a page named 5486-.php and coded as below

$link = mysql_connect(‘hostname’,’dbuser’,’dbpassword’);
if (!$link) {
die(‘Could not connect to MySQL: ‘ . mysql_error());
echo ‘5486’; mysql_close($link);

On each visit this page checks availability of SQL server (in case of free host SQL is first cause of website downtime), So if server is unavailable then it will give errror, Or will output as 5486 (we are going to use this output in next step, so record it properly),
NOTE : If you want to use above codes then dont forget to change hostname, dbuser, dbpassword with yours.

Enter first four numbers expected in output (prefer numeric values) in above case its 5486, On each run servers checks output of entered page url is matching or not, if matched it will increase server health, or Zero out if not matched.

Domain/SubDomains name you wish to monitor

Alert Settings, Enter YES to enable or leave blank to disable, To enable SMS alerts you have to signup for Google calendar service, set email address to receive alerts in email.

NOTE : SMS alerts are limited to sms standards, so you may not actual server response.

Now Open Tools menu

Screenshot of tools menu - Failover with Google Docs

Click Script editor, New window/Tab will opened

Screenshot of script triggers menu - Failover with Google Docs

Click on Current script’s triggers…

Screenshot of Current script's Triggers - Failover with Google Docs

Click on No triggers setup. Click here to add one now.

Screenshot of timings - Failover with Google Docs

at first you will see only one row, click Add a new trigger to add one more row, and set as above, Only two functions healthcheck and detectip have to trigger timely, Other function are called internally dont try to drive them with this form.

NOTE : if you have static ip’s only then you need not to trigger detectip function timely, just use it once to fetch ip’s, and DONOT set it to trigger often an hour is recommended.

Now click Save

Screenshot of Authorization - Failover with Google Docs

Authorize it

Screenshot of Grant access page - Failover with Google Docs

Check Learn more if you want, Then Grant access and close it.

Now close script Window/Tab, Everything is done, Now relax.

Script periodically do tasks and will report it in Reports sheet (Repeated responses will not be logged), and if set SMS, Email alerts then alert so.

Filled Example

Example - Failover with Google Docs

IMPORTANT NOTE : Never share filled form or you will accidentally expose your dns login.

Script is tested personally and found working as expected, but may have errors, feel free to contact. Download project files

UPDATE 1 : Google Docs is now Google Drive