Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

EWD 3 Training Course Part 29: Running QEWD as a Service

453 views

Published on

This presentation is Part 29 of the EWD 3 Training Course. It explains how to run QEWD Node.js as a background service on Windows and Linux systems, instead of running it as a foreground process in a Command Prompt or Terminal window.

Published in: Software
  • Be the first to comment

  • Be the first to like this

EWD 3 Training Course Part 29: Running QEWD as a Service

  1. 1. Copyright © 2016 M/Gateway Developments Ltd EWD 3 Training Course Part 29 Running QEWD as a Service Rob Tweed Director, M/Gateway Developments Ltd Twitter: @rtweed
  2. 2. 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
  3. 3. 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
  4. 4. Copyright © 2016 M/Gateway Developments Ltd Running QEWD as a Service • Windows: – NSSM • Linux – PM2
  5. 5. 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)
  6. 6. 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 Filesnodejs
  7. 7. Copyright © 2016 M/Gateway Developments Ltd Log file for piped output • Create a suitable directory, eg: – C:qewdlog • Create an empty file in it: – qewd.log
  8. 8. 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
  9. 9. 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
  10. 10. Copyright © 2016 M/Gateway Developments Ltd Start NSSM Installer • In a Command Prompt window type: nssm install • Application Path: – C:Program Filesnodejsnode.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:qewdlogqewd.log – Error: C:qewdlogqewd.log • Give your new service a name: – QEWD • Click Install Service
  11. 11. 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
  12. 12. Copyright © 2016 M/Gateway Developments Ltd Log File • Look in C:qewdlogqewd.log • You should see all the console.log activity being piped there
  13. 13. 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
  14. 14. 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
  15. 15. 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
  16. 16. Copyright © 2016 M/Gateway Developments Ltd Start QEWD as a Service cd ~/qewd pm2 start qewd.js Assuming that qewd.js is the name of your QEWD startup file.
  17. 17. Copyright © 2016 M/Gateway Developments Ltd Start QEWD as a Service cd ~/qewd pm2 start qewd.js This will be now the PM2 Service name
  18. 18. Copyright © 2016 M/Gateway Developments Ltd Monitor PM2 Services cd ~/qewd pm2 status Displays the status of all your PM2 Services - online - stopped
  19. 19. Copyright © 2016 M/Gateway Developments Ltd Stop the QEWD PM2 Service cd ~/qewd pm2 stop qewd
  20. 20. Copyright © 2016 M/Gateway Developments Ltd Restart the QEWD PM2 Service cd ~/qewd pm2 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
  21. 21. Copyright © 2016 M/Gateway Developments Ltd Restart the QEWD PM2 Service cd ~/qewd pm2 restart qewd To stop and start QEWD again in 1 command
  22. 22. 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
  23. 23. 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
  24. 24. 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
  25. 25. 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

×