As part of A2 Hosting Perpetual Security, long running processes are periodically terminated on our cPanel Shared and Reseller servers. This includes node.js applications. Learn how to keep your node.js application up and running with this article.
The preferred method for making persistent node.js applications on cPanel Shared and Reseller servers is to use the Node.js selector. Learn to setup a node.js application using the Node.js selector with this article.
Sometimes an application must be run on a specific port and the Node.js selector cannot be used. Popular methods of creating persistent node.js applications like PM2 and Forever are also processes. They are subject to periodic termination and so cannot be relied on to be available to restart node if it should be terminated.
Cron jobs run periodically and are not terminated and so can be counted on to restart a terminated node.js process. Follow thses steps to create a cron job to restart your node application:
Under Cron Email, type the e-mail address where you want to receive notifications, and then click . Every time the cron job runs, the e-mail account receives a message.
In the Command text box, type the following command, replacing mylock, app_directory, and startup_file with the correct values for your own application:
/usr/bin/flock -n /tmp/mylock.lock ${HOME}/nodejs/bin/node ${HOME}/app_directory/startup_file.js
The flock command used in this example checks to see if the node instance is still running before attempting to start a new instance. As long as the original process is still running, a new one is not started. This avoids port contention issues that can interrupt the application and generate errors.
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.
Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.
We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.