Upload
rob-tweed
View
142
Download
0
Embed Size (px)
Citation preview
Copyright © 2016 M/Gateway Developments Ltd
EWD 3 Training CoursePart 29
Running QEWD as a Service
Rob TweedDirector, M/Gateway Developments Ltd
Twitter: @rtweed
Copyright © 2016 M/Gateway Developments Ltd
The QEWD Node.js process
• So far we've run it in a Command Prompt or Terminal window– This OK for demonstration– But not for production
• It needs to run as a service– Automatically start at boot time– Restart on error– Pipe console.log to a log file
Copyright © 2016 M/Gateway Developments Ltd
Running QEWD as a Service
• Different approaches needed for– Windows– Linux
• Many different options available, but the following are two that seem to work well
Copyright © 2016 M/Gateway Developments Ltd
Running QEWD as a Service
• Windows:– NSSM
• Linux– PM2
Copyright © 2016 M/Gateway Developments Ltd
Windows: NSSM
• http://nssm.cc/
• Free Service Manager for Windows• Works very well with Node.js and QEWD
• Click download and get the latest version– 2.24 (at time of writing these notes)
Copyright © 2016 M/Gateway Developments Ltd
Install NSSM
• Drill down into the downloaded file– Downloads/nssm-2.24.zip
• Find the /win64 directory– Downloads/nssm-2.24.zip/nssm-2.24/win64/nssm.exe
• Copy nssm.exe to a directory that is already in your PATH for executables, eg:– C:\Program Files\nodejs
Copyright © 2016 M/Gateway Developments Ltd
Log file for piped output
• Create a suitable directory, eg:– C:\qewd\log
• Create an empty file in it:– qewd.log
Copyright © 2016 M/Gateway Developments Ltd
Dependency on Caché
• When NSSM starts up, it must wait to make sure Caché has already started– We need the dependency information
• Control Panel:– System and Security
• Administrative Tools– Services
Copyright © 2016 M/Gateway Developments Ltd
Dependency on Caché
• In the Services Window that opens up, find the Service named:– Caché Controller for Cachexxxx
• Right click on it and select Properties• At the top you'll see the Service Name
– eg: Cache c- intersystems_cache2015-2• Copy this to your clipboard
Copyright © 2016 M/Gateway Developments Ltd
Start NSSM Installer• In a Command Prompt window type:
nssm install• Application Path:
– C:\Program Files\nodejs\node.exe• Startup Directory:
– C:\ewd3 (or wherever you start ewd-xpress)• Arguments:
– ewd-xpress• Click on Dependencies Tab
– Paste the Caché Service string from clipboard
• Click on I/O tab– Input: leave blank– Output: C:\qewd\log\qewd.log– Error: C:\qewd\log\qewd.log
• Give your new service a name:– QEWD
• Click Install Service
Copyright © 2016 M/Gateway Developments Ltd
Start the QEWD Service• Switch to the Services window• Click Refresh button• QEWD should appear in the list of services• Right-click on it and select Properties
– Service Status will be stopped– Click Start
• QEWD should now be running– Test by starting the qewd-monitor application
Copyright © 2016 M/Gateway Developments Ltd
Log File
• Look in C:\qewd\log\qewd.log• You should see all the console.log activity
being piped there
Copyright © 2016 M/Gateway Developments Ltd
Controlling the Service• Standard Windows Service• Use the Services panel and find QEWD
– Stop– Start– Restart
• If an error occurs that stops the master process, the QEWD service will automatically restart
• The QEWD service will start automatically when Windows is re-booted
Copyright © 2016 M/Gateway Developments Ltd
NSSM additional features
• Lots more functionality• Worth exploring documentation at
http://nssm.cc
• To edit your service definition:– Open Command Prompt window
nssm edit QEWD
Copyright © 2016 M/Gateway Developments Ltd
Linux: PM2
• Advanced Node.js Process Manager– http://pm2.keymetrics.io/
• Install:
– -g option makes pm2 available as a command
cd ~sudo npm install –g pm2
Copyright © 2016 M/Gateway Developments Ltd
Start QEWD as a Service
cd ~/qewdpm2 start qewd.js
Assuming that qewd.js is the name of yourQEWD startup file.
Copyright © 2016 M/Gateway Developments Ltd
Start QEWD as a Service
cd ~/qewdpm2 start qewd.js
This will be now the PM2 Service name
Copyright © 2016 M/Gateway Developments Ltd
Monitor PM2 Services
cd ~/qewdpm2 status
Displays the status of all your PM2 Services- online- stopped
Copyright © 2016 M/Gateway Developments Ltd
Stop the QEWD PM2 Service
cd ~/qewdpm2 stop qewd
Copyright © 2016 M/Gateway Developments Ltd
Restart the QEWD PM2 Service
cd ~/qewdpm2 start qewd
If you've already started QEWD as a service,and if it appears as stopped in pm2 status,
you don't need to specify the .js file extension
Copyright © 2016 M/Gateway Developments Ltd
Restart the QEWD PM2 Service
cd ~/qewdpm2 restart qewd
To stop and start QEWD again in 1 command
Copyright © 2016 M/Gateway Developments Ltd
Logging the output
• PM2 automatically pipes console.log and error output to log files:
– ~/qewd/.pm2/logs
– You should find:• ~/.pm2/logs/qewd-out-0.log
Copyright © 2016 M/Gateway Developments Ltd
Logging the output
• PM2 automatically pipes console.log and error output to log files:
– ~/qewd/.pm2/logs
– You should find:• ~/.pm2/logs/qewd-out-0.log
This number may vary
Copyright © 2016 M/Gateway Developments Ltd
Logging the output
• Use the tail command to monitor QEWD activity in real-time
tail –f ~/.pm2/logs/qewd-out-0.log
Copyright © 2016 M/Gateway Developments Ltd
PM2 will auto-restart QEWD
• If an error brings down the QEWD master process, PM2 will automatically restart it
• Try stopping the master process using qewd-monitor while tailing the log file– Watch it stop and immediately restart