Cirkus Serveri Forum
    • CoD4xAdmin
    • Recent
    • Popular
    • Groups
    • Users
    • Register
    • Login

    Keep application alive forever with PM2

    Scheduled Pinned Locked Moved
    Tutorials
    1
    1
    1.3k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • NeHoN
      NeHo Administrators
      last edited by

      PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.

      More info: https://www.npmjs.com/package/pm2

      Installing PM2 and starting our application

      To install PM2 enter next command

      npm install pm2 -g
      

      After the installation lets start our application with PM2, we will also add a name for our website, in this case it is named cod4xwebadmin

      Navigate to the application root and type (if you have multiple applications repeat the step for each)

      pm2 start npm --name "cod4xwebadmin" -- start
      

      Our application is now started, even if we exit putty the website will still be alive.

      PM2 Commands

      Since we added a name cod4xwebadmin we can now execute pm2 commands only for this application (if you run multiple applications you can add a unique name for every application and this way you can handle them individually)

      Some basic commands:

      Start the cod4xwebadmin application

      pm2 start npm --name "cod4xwebadmin" -- start
      

      Stop

      pm2 stop cod4xwebadmin
      

      See the console log when it is started

      pm2 log cod4xwebadmin
      

      if you would have another application differently named then replace cod4xwebadmin with the correct name

      Or if you would like to start | stop all applications at once you can use all instead the application names, for example stop all applications you type

      pm2 stop all
      

      What if i restart my server, will the application be started automatically?

      In order to start on system boot we need to execute next commands
      Make sure you have started all applications and they run before you execute the commands

      To detect available init systems on your machine and generate a configuration, use:

      pm2 startup
      

      Save your process list with:

      pm2 save
      

      That's it, with this 2 commands our website will automatically start on system start

      I keep hitting the 'Escape' key - but I'm still here. ...

      1 Reply Last reply Reply Quote 0
      • First post
        Last post

      0

      Online

      191

      Users

      268

      Topics

      1.2k

      Posts
      Powered & Designed by NeHo