Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PM2 presentation @JSCONF.asia

PM2 presentation @JSCONF.asia

PM2 feature overview, tips and module system

Alexandre Strzelewicz

November 19, 2015
Tweet

Other Decks in Programming

Transcript

  1. • CEO & Founder at • Author of • Full

    Stack Javascript developer • Technologist
  2. Deploying to production is complex • Oh noes why my

    app only use 10% of my server CPUs? • Oh noes which app is leaking memory? • Why the server went out of memory? • Oh noes my app crashed! • Where are my damn logs? • How do I organize my micro service app? • …. …. …. ….
  3. App #1 App #2 App #3 App #4 App #1

    App #3 App #4 CL1 CL2 CL3 CL4 Disorganized application & workflow Structured application & workflow To Before After
  4. App #1 App #3 App #4 Usability CPU Memory Log

    Deployment Modules CL1 CL2 CL3 CL4 Ressources management and optimization Easier software management Extend capabilities
  5. PM2: Some figures • 10.000+ stars on GitHub • 2.000.000+

    downloads • 2500+ commits • 120+ contributors • 750+ tests
  6. Setup PM2 No setup required! But… $ pm2 completion install

    Enabling autocompletion: $ pm2 startup Respawning PM2 on server boot: http://pm2.keymetrics.io/docs/usage/quick-start/
  7. Launching a Node.js application $ pm2 start app.js Put application

    in background Handle logs Monitor Auto respawn application
  8. Launching any kind of application $ pm2 start app.py —interpreter="python3"

    $ pm2 start script.sh Starting a bash script: Starting a Python app & set interpreter http://pm2.keymetrics.io/docs/usage/process-management/
  9. Acting on processes $ pm2 delete <app-name|app-id|'all'> $ pm2 restart

    <app-name|app-id|'all'> Restart: Delete: $ pm2 stop <app-name|app-id|'all'> Stop: http://pm2.keymetrics.io/docs/usage/process-management/
  10. Starting an application cluster mode $ pm2 start app.js -i

    <instances> http://pm2.keymetrics.io/docs/usage/cluster-mode/
  11. Managing clustered applications $ pm2 gracefulReload <app-name|'all'> $ pm2 reload

    <app-name|'all'> Reload without downtime: Graceful Reload (send signal to process): $ pm2 scale <app-name> <instances> Scale up/down process number: http://pm2.keymetrics.io/docs/usage/cluster-mode/
  12. Inspecting logs $ pm2 flush $ pm2 logs [app-name] Display

    logs in realtime: Flushing logs: $ pm2 reloadLogs Reloading logs (logrotate): http://pm2.keymetrics.io/docs/usage/log-management/
  13. Starting your micro service app… $ DEBUG=“*” NODE_ENV="production" pm2 start

    app-1.js — name “API” -i 8 —watch —max-memory-restart=“300M” — -a 23 $ DEBUG=“app2:*” NODE_ENV=“production" pm2 start app-2.js —name “WORKER" —watch — -a prod $ DEBUG=“app3:*” NODE_ENV=“production" pm2 start app-3.js —name “BDD" —watch — -a malo
  14. Using the JSON declaration $ pm2 restart ecosystem.json $ pm2

    start ecosystem.json Start: Restart: $ pm2 stop <app-name|app-id|'all'> Stop: http://pm2.keymetrics.io/docs/usage/application-declaration/
  15. Deployment commands $ pm2 deploy ecosystem.json production $ pm2 deploy

    ecosystem.json production setup Setup remote server: Update remote application: Revert to the n-th deployment: $ pm2 deploy ecosystem.json production revert [n] http://pm2.keymetrics.io/docs/usage/deployment/
  16. What is a module? An app that extend PM2 capabilities

    or A worker process providing an API or A totally independant software
  17. Installing a module $ pm2 install <module-name> It gets the

    module from NPM then Start it and Keep it alive forever http://docs.keymetrics.io/docs/usage/building-module/
  18. Managing modules $ pm2 uninstall <module-name> $ pm2 install <module-name>

    Install a module: Uninstall: $ pm2 set <module-name>:<attr> <value> Set configuration option: http://docs.keymetrics.io/docs/usage/building-module/
  19. Module #1: pm2-logrotate $ pm2 install pm2-logrotate Automatically rotate all

    logs of applications managed by pm2 https://github.com/pm2-hive/pm2-logrotate
  20. Module #2: pm2-webshell $ pm2 install pm2-webshell Expose a fully

    capable terminal in your browser https://github.com/pm2-hive/pm2-webshell
  21. Writing your own module $ pm2 module:generate sample-module Create a

    sample module: Documentation: Google -> pm2 module system Official modules repositories: http://github.com/pm2-hive/