Starting up the ZigBee Survey Tool together with the System

This post describes how to startup the ZigBee Site Survey Tool (or any other node.js script, like the Qwesta Weather station) together with the system using PM2. This was verified with the Raspberry Pi (Rasbian Jessie and Ubuntu Mate) and a Desktop PC running Ubuntu 14.04.

Prerequisites

Node.js (version 4 or later) must be installed on your system. For the Raspberry Pi, see this article how to install a recent version.

Install PM2

PM2 is a process manager from Keymetrics. Install it globally using nodes packet manager npm:

sudo npm i -g pm2

Test the installation with pm2, the tool should display the help text in the console.

Setup

Tell pm2 that we want to instantiate it as service, running for user “pi”. Right now (April 2015) you have to add your home directory with the –hp option, otherwise the creation of the startup script fails (taking the home directory of root, see GitHub Issue 1888 for details):

sudo pm2 startup -u pi --hp /home/pi

Create a file processes.json in your home directory with the following content (assuming that you installed the ZigBee Site Survey as described in this article).

{
 apps:[
   {
     "name": "zigbee",
     "script": "~/ZigBeeSiteSurvey/server.js"
   }
 ]
}

Start the survey:

pm2 start processes.json

You can check the state of the processes managed by PM2 anytime:

pm2 ls

Now we tell PM2 that we want it to restart the current process configuration when the system boots

pm2 save

That’s it. Restart your system and verify with pm2 ls that the tool is running.

Advanced features

We used only some very basic features of PM2, there are a lot more features worth to discover.  See the official PM2 page: http://pm2.keymetrics.io/