pm2

How to force pm2 to restart after a specific amount of time?

这一生的挚爱 提交于 2019-12-03 21:53:01
I am using PM2 to keep my node.js apps running. Is there any way to have PM2 restart my app every 1 hour? Tomislav Stankovic Put the code below in pm2.js and start it with pm2 start pm2.js var pm2 = require('pm2'); pm2.connect(function(err) { if (err) throw err; setTimeout(function worker() { console.log("Restarting app..."); pm2.restart('app', function() {}); setTimeout(worker, 1000); }, 1000); }); More about this can be found here . Additional resources: How can I programmatically shutdown a node program and restart it? Programmatically watch and restart node server 来源: https://stackoverflow

Make pm2 log to console

家住魔仙堡 提交于 2019-12-03 14:57:05
问题 I am running a node webserver using pm2. Since pm2 spawns another process and redirects stdout and stderr to files, I have to look somewhere else for the logs. Ideally, I would like to have the node process output to the same console window that I've run pm2 from. Otherwise, I would settle for pm2 run the node process with an active console window and have stdout and stderr of the node process write to that console window. How can this be achieved? I'm on a windows machine. 回答1: I believe you

permission denied, mkdir in container on openshift

隐身守侯 提交于 2019-12-03 14:44:50
I have a container with nodejs and pm2 as start command and on OpenShift i get this error on startup: Error: EACCES: permission denied, mkdir '/.pm2' I tried same image on a Marathon hoster and it worked fine. Do i need to change something with UserIds? The Dockerfile: FROM node:7.4-alpine RUN npm install --global yarn pm2 RUN mkdir /src COPY . /src WORKDIR /src RUN yarn install --production EXPOSE 8100 CMD ["pm2-docker", "start", "--auto-exit", "--env", "production", "process.yml"] Update the node image already creates a new user "node" with UID 1000 to not run the image as root. I also tried

Load balancing since Node v0.12.2 - cluster, pm2 or nginx

自闭症网瘾萝莉.ら 提交于 2019-12-03 13:08:14
问题 With Node v0.12.2, the cluster module supports Round-Robin (RR) load balancing, which ensures load is more evenly distributed than the previous OS-level load balancing. So now we are spoilt for choice: Use the cluster module Use pm2 which uses the cluster module under the hood Use nginx Use HAProxy I am aware of this excellent post as well as other answers here on SO, but none have addressed the newer Cluster module with RR mode. So the question boils down to: Judging only on their load

记一次完整的项目部署

删除回忆录丶 提交于 2019-12-03 12:08:28
前段时间在公司部署项目的时候,运维同学说了一堆关于服务器的东西,顿时感觉不知所云,云里雾里。。。 索性拿这个项目练习一下,简单了解项目部署到服务器的这个流程是怎么处理的 预备知识 pm2 pm2 是启动node进程管理工具 常用命令 ··· pm2 start app.js : 启动服务,入口文件是app.js pm2 list 查看有哪些进程启动 pm2 show xxx 查看某一个服务的详情 npm restart [name or id] : 重启服务 pm2 monit : 对服务进行监控 ··· 一个项目的package.json 文件 平时启动服务我们可以使用 node run app.js 如果借助pm2 来启动服务 就可以输入 pm2 start app.js 在命令行输入 pm2 list 可以查看正在运行的项目 pm2支持配置文件启动 script 启动脚本路径 exec_mode 应用启动模式,支持fork和cluster模式 instances 应用启动实例个数,仅在cluster模式有效,默认为fork fork和cluster模式 fork为单进程 cluster可以启动多个进程 在项目中新增一个pm2配置文件 pm2.config.json { "name": "mxx-project", "script": "./index.js", "error

PM2 (Node.js) not listening on specified port

余生长醉 提交于 2019-12-03 11:43:23
问题 I am trying to get a Node/Express application up and running on PM2. I can start the application fine with this command: npm start This starts the app fine on port 3000. If I try to start the application with pm2 start app.js I get the following in the log: { online: true, success: true, pid: 10714, pm2_version: '0.8.15' } 2014-06-12T19:52:06.789Z : [[[[ PM2/God daemon launched ]]]] 2014-06-12T19:52:06.800Z : RPC interface [READY] on 6666:localhost 2014-06-12T19:52:06.801Z : BUS system [READY

How to specify a port number for pm2

好久不见. 提交于 2019-12-03 11:00:49
问题 I'm trying to use pm2 to manage a node.js cluster pm2 start . -i 3 I'm currently running the app on heroku and using a Procfile with the above command, but I cannot figure out how to configure pm2 to use the existing PORT env var. Something like pm2 start . -p $PORT What am I missing? 回答1: You can use environment variable. For example: 1) NODE_PORT=3002 pm2 start -I 0 app.js 2) Read value in app: console.log(process.env.NODE_PORT); Or, if you are build express app: 1) PORT=3002 pm2 start -I 0

PM2 on vagrant - starting app AFTER shared folder is mounted

匿名 (未验证) 提交于 2019-12-03 10:10:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: How can I set PM2 to start the app after the shared directories get mounted? By default pm2 startup adds script which try to run script right after OS boot, which causes program error (because the folder is not yet mounted by that time). 回答1: you can add the following line in your Vagrantfile config . vm . provision : shell , : inline => "pm2 start /vagrant/project/server/index.js && pm2 startup" , : run => 'always' , privileged : false read about shell provisioning : inline (string) - Specifies a shell command inline to execute on

学习Express之部署express-demo

烈酒焚心 提交于 2019-12-03 09:53:46
一、服务器准备 服务器ip地址为:172.16.70.174 1.安装 Node.js 参考: http://my.oschina.net/songzhu/blog/608129 2.安装 PM2 PM2 是一个带有负载均衡功能的 Node 应用的进程管理器。 全局安装 PM2 $ npm install pm2 -g $ pm2 list [PM2] Spawning PM2 daemon [PM2] PM2 Successfully daemonized ┌──────────┬────┬──────┬─────┬────────┬─────────┬────────┬────────┬──────────┐ │ App name │ id │ mode │ pid │ status │ restart │ uptime │ memory │ watching │ └──────────┴────┴──────┴─────┴────────┴─────────┴────────┴────────┴──────────┘ Use `pm2 show <id|name>` to get more details about an app 安装 PM2 如果出现错误,大概是网络和权限问题导致的。仔细看一下错误提示,如果是网络问题,那么多重试几次应该就可以了。 3.准备发布目录

Make pm2 log to console

我只是一个虾纸丫 提交于 2019-12-03 09:46:10
I am running a node webserver using pm2. Since pm2 spawns another process and redirects stdout and stderr to files, I have to look somewhere else for the logs. Ideally, I would like to have the node process output to the same console window that I've run pm2 from. Otherwise, I would settle for pm2 run the node process with an active console window and have stdout and stderr of the node process write to that console window. How can this be achieved? I'm on a windows machine. I believe you can also see the stdout and stderr of a process that is running daemonized by the command pm2 logs or pm2