pm2

Can the pm2 node module restarts the app after crash automatically

流过昼夜 提交于 2019-12-03 09:32:57
I have a node app ready which is workable, but has known and unknown bugs which crashes the node app. In such cases it would be nice if pm2 can restart the node app. Is this feature already available in pm2 ? Yes, it does this by default and there is even a watch option to restart on changes. Also, check new excellent option --exp-backoff-restart-delay=100 (msec, not sec!) pm2 will restart crashed app after 100 msec, then step-by-step increase restart-delay to 15 secunds This may help: # Generate Startup Script $ pm2 startup # Freeze your process list across server restart $ pm2 save # Remove

博客网站项目部署问题汇总

限于喜欢 提交于 2019-12-03 09:32:07
最近在使用koa2+mysql+nodejs+weback+vue+redis技术搭建了一个博客网站,奈何遇到了种种问题,现在一一总结一番: 问题1. 使用 ecosystem.json 配置文件部署项目, " post-deploy " : " npm install && pm2 startOrRestart ecosystem.json --env production " , // 项目发布到服务器上执行的命令 发现按照教程或者网络给出的配置文件,无法访问网站,网站报nginx代理问题,或者直接502 Bad Gateway ; 打印 pm2 的日志: 发现服务貌似一直被 killed 然后在唤起,然后在killed。。。。。 问题2.于是修改配置文件,怀疑是执行命令的问题: "post-deploy" : "npm install &&npm run prd &&pm2 startOrRestart ecosystem.json --env production", //项目发布到服务器上执行的命令 注意这里多了 npm run prd,对应的package.json 文件中的命令: "prd": "cross-env NODE_ENV=production pm2 start bin/www --watch", 即让服务启动的命令,然后页面就能访问了,但是会有几个问题:

custom logging under pm2

匿名 (未验证) 提交于 2019-12-03 08:39:56
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have some useful logging in my node app that I write to console.log node server.js >> /var/log/nodeserver.log 2>&1 However, when trying the same under pm2 : pm2 start server.js >> /var/log/pm2server.log 2>&1 the log file only shows the pm2 startup information Is application logging at all possible with pm2 ? On their page they discuss logging, and show an image with text like "log message from echo.js" , but I see nothing about getting custom information into the pm2 log. 回答1: When running with pm2 your application logs will reside in

what is the point of using pm2 and docker together?

走远了吗. 提交于 2019-12-03 07:48:18
问题 We have been using pm2 quite successfully for running apps on our servers. We are currently moving to docker and we saw http://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs/ But what is the point of actually using both together? Does not docker provide everything pm2 does? 回答1: Usually there is no point in using pm2 inside of a docker. Both PM2 and Docker are a process managers and they both can do logs forwarding, restart crashed workers and many other things. If you run pm2 inside of a

pm2 not working with experimental-modules flag

倖福魔咒の 提交于 2019-12-03 07:15:18
I am using ES6 modules by adding the --experimental-modules arguments to Node. Running node --experimental-modules app.mjs works perfectly fine. However, when I run the same command with pm2 I get the following error: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module My current pm2 config file looks like this: "apps": [ { "name": "api", "script": "app.mjs", "exec_mode": "cluster", "instances": "max", "node_args": "--experimental-modules", "env": { variables here.. } } ], I have also tried using esm instead like this: "node_args": "-r esm" In both cases they return the same [ERR

node工具之pm2

送分小仙女□ 提交于 2019-12-03 06:38:21
pm2 PM2是带有内置负载平衡器的Node.js应用程序的生产过程管理器。它使您可以使应用程序永远保持活动状态,无需停机即可重新加载它们,并简化常见的系统管理任务。 安装 npm install pm2 -g 常用命令 pm2 start app.js 开启进程 pm2 list 所有进程 pm2 stop <app_name|id|'all'|json_conf> / all 停止 pm2 restart <app_name|id|'all'|json_conf> 重启 pm2 delete <app_name|id|'all'|json_conf> 删除 pm2 describe <id|app_name> 单一进程 pm2 show <id|app_name> 单一进程 pm2 monit 监控 cpu 和内存使用情况 pm2 reload all 重开进程 pm2 logs 日志信息 pm2 flush 清理日志信息 pm2 reloadLogs pm2 startup 开机自启动 pm2 save 保存进程状态 pm2 unstartup 取消开机自启动 pm2 install 安装模块 pm2 update 更新 执行npm命令 pm2 start npm -- start pm2 start npm --no-automation --name {app name}

How to make a cron job with PM2

为君一笑 提交于 2019-12-03 04:52:23
问题 I want to make a cron job to send mail every 15 minutes taking data from a database table. In node js I can make a cron job but through PM2 I don't understand where to place the code and how it works. 回答1: Use the --cron option: -c --cron <cron_pattern> For example: pm2 start sendMail.js --cron "*/15 * * * *" Pm2 will now restart the sendMail.js script on the hour, and at 15, 30 and 45 minutes past the hour 回答2: If you use PM2 ecosystem then in the config file add cron sequence to script

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

久未见 提交于 2019-12-03 03:24:09
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 balancing capabilities, should I use pm2 or nginx ? TL;DR If it's just pm2 vs. nginx go for nginx. Better :

How to run a python script like pm2 for nodejs

匿名 (未验证) 提交于 2019-12-03 02:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've used pm2 for my Node.js script and I love it. Now I have a python script which collect streaming data on EC2. Sometimes the script bombs out and I would like a process manager to restart itself like pm2. Is there something the same as pm2 for python? I've been searching around and couldn't find anything. Here's my error File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 430, in filter self._start(async) File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 346, in _start self._run() File "/usr

How to use Grunt/Gulp with pm2?

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: pm2 is a great tool to manage node apps. How does it work with grunt/glup ? I didn't find any useful clues after Googling for 20 minutes. 回答1: If I understand your question well, it seems you want to deploy your app. Since pm2 0.9 deployment can be done with pm2 deploy see README . In the case of grunt/gulp, I see two options: You've your node_modules comitted. Using pm2 deploy run your gulp process from the post-deploy section: "post-deploy" : "node ./node_modules/gulp/bin/gulp.js ./GulpFile.js && pm2 startOrRestart ecosystem.json --env