pm2 經常使用命令解析

https://blog.csdn.net/chengxuyuanyonghu/article/details/74910875node

(以上基本命令解析,一下補充)git

pm2 ecosystem  #在當前目錄下生成一個ecosystem.config.js文件github

-------------------------------------------------------------------------------------------npm

module.exports = {
  apps : [{
    name: 'jjj',                    #爲啓動node的名字,須要本身修改
    script: '/root/nodetest/test2.js',          #啓動js文件或腳本的路徑,須要本身修改

    // Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
    args: 'one two',
    instances: 2,                #建立實例的個數
    autorestart: true,
    watch: true,
    max_memory_restart: '1G',
    env: {
      NODE_ENV: 'development'
    },
    env_production: {
      NODE_ENV: 'production'
    }
  }],

  deploy : {
    production : {
      user : 'node',
      host : '212.83.163.1',
      ref  : 'origin/master',
      repo : 'git@github.com:repo.git',
      path : '/var/www/production',
      'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production'
    }
  }
};           #apps:[] 這個能夠有多個,就能夠啓動多個項目app

-------------------------------------------------------------------------------------------------post

pm2 start ecosystem.config.js   #便可以啓動nodejs進程.net

pm2 startup #設置開機自啓動,會生成service文件,就能夠哦那個systemcel管理,原理是rest

    (ExecStart=/usr/local/nodejs/lib/node_modules/pm2/bin/pm2 resurrect
     ExecReload=/usr/local/nodejs/lib/node_modules/pm2/bin/pm2 reload all
        ExecStop=/usr/local/nodejs/lib/node_modules/pm2/bin/pm2 killblog

    因此要想讓新增的nodejs開機自啓,就先要 pm2  save 一下進程

相關文章
相關標籤/搜索