pm2

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

你说的曾经没有我的故事 提交于 2019-12-05 08:08:53
问题 I am using PM2 to keep my node.js apps running. Is there any way to have PM2 restart my app every 1 hour? 回答1: 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

node.js中http模块、koa、pm2、nginx、域名 的关系

孤者浪人 提交于 2019-12-05 04:48:24
如果我们想要自己搭建一个服务器,上面这些名词应该是我们经常会听到的,他们之间有什么关系呢? node.js http模块 基础支持 koa 路由 静态文件 权限 中间件 模板 文件上传 Gzip压缩 pm2 热启动 单机负载均衡 监听 nginx 集群负载均衡 反向代理 虚拟主机 Gzip压缩 域名 服务器于用户之间的连接 来源: https://www.cnblogs.com/mrzhu/p/11907200.html

Is there a way to restart pm2 process using cron but only if it's not already running?

落花浮王杯 提交于 2019-12-05 04:17:14
I want to restart my Node.Js app using PM2 through pm2 restart app.js using crontab but ONLY if the app is not already running (e.g. if my server crashed and restarted and pm2 didn't restart). the command above restarts it anyway even if it's running. How do I fix it? UPDATE I do not want my app to restart if it's already running. I want it to restart only if it's listed as "stopped" or if it is not running. Some suggestions offer to write a bash script, but what would it be? I tried the options below, but they either don't work or restart the app even if it's running. The better way of doing

阿里云CentOS7.x安装nodejs及pm2

做~自己de王妃 提交于 2019-12-05 02:24:36
对之前文章的修订 您将了解 CentOS下如何安装nodejs CentOS下如何安装NVM CentOS下如何安装git CentOS下如何安装pm2 适用对象 本文档介绍如何在阿里云CentOS系统的云服务器ECS实例上,安装Nodejs并部署项目。 准备工作 部署之前,请做如下准备工作: 购买ECS实例 您的实例运行的镜像是CentOS7.x 您的实例可以连接公网 本地已经安装用于连接 Linux 实例的工具,如 Xshell 基本流程 使用云服务器 ECS 安装Nodejs并部署项目的操作步骤如下: 购买 ECS 实例。 部署Node.js环境-二进制文件安装。 部署Node.js环境-使用NVM安装多版本。 部署测试项目。 注:2和3步骤,根据您的实际应用场景,任选其一。 操作步骤 步骤 1:创建ECS实例 选择操作系统为公共镜像CentOS7.x。使用root用户登录Linux实例。 步骤2:部署Node.js环境—二进制文件安装 该部署过程使用的安装包是已编译好的二进制文件,解压之后,在bin文件夹中就已存在node和npm,无需手工编译。 安装nodejs步骤 wget命令下载Node.js安装包。 选择自己需要安装的版本 https://nodejs.org/dist/ 选择带 linux-x64.tar.xz 的安装包,该安装包是编译好的文件,解压之后

Wait for mongodb to be ready before starting pm2 process on reboot

醉酒当歌 提交于 2019-12-04 14:35:07
I am having trouble making pm2 wait for mongodb to be ready before it starts a process on system reboot. (I am using Ubuntu 16.04 server) In my systemd service file for pm2 I have this, which I thought would make it wait until after mongodb was started: [Unit] Description=PM2 process manager Documentation=https://pm2.keymetrics.io/ Wants=mongod.service After=network.target mongod.service [Service] Type=forking But it seems that it runs pm2, and therefore the node.js processes that pm2 launches before the mongodb actually is ready to listen on 27017. My error logs show that my node.js script

pm2 not working with experimental-modules flag

时光怂恿深爱的人放手 提交于 2019-12-04 11:44:25
问题 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

NodeJS on multiple processors (PM2, Cluster, Recluster, Naught)

半腔热情 提交于 2019-12-04 09:34:43
问题 I am investigating options for running node in a multi-core environment. I'm trying to determine the best approach and so far I've seen these options Use built in cluster library to spin up works and respond to signals Use PM but, PM2 -i is listed as beta. Naught Recluster Are there other alternatives? What are folks using in production? 回答1: I've been using the default cluster library, and it works very well. I've had over 10,000 concurrents(multiple clusters on multiple servers) and it

云服务器部署nodejs项目

一笑奈何 提交于 2019-12-04 03:47:34
2019年双十一被别人骗买了一台云服务器,一年只要86元钱,有兴趣的点击连接https://www.aliyun.com/1111/2019/group-buying-share?ptCode=3C05AC6660F8A9085026B2602C1FAD93647C88CF896EF535&share_source=copy_link进去购买,双十一第一次购买有优惠。 云服务器部署nodejs项目,我选的是centOS的liunx安装系统 1:进入远程连接安装nodejs,由于本地安装失败,我采用yum安装成功, 安装命令 yum install -y nodejs这时默认安装node版本太低,要升级到指定版本,执行命令curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash yum -y install nodejs再重启一下云服务器,参考https://www.jianshu.com/p/e9db0baf781b2:运行云服务器上的nodejs项目,例如1.js文件,直接cd 到文件夹下执行node 1.js并在云服务器上开启对应端口,具体参考https://blog.csdn.net/a909301740/article/details/79145146

custom logging under pm2

☆樱花仙子☆ 提交于 2019-12-04 01:54:25
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. When running with pm2 your application logs will reside in $HOME/.pm2/logs as described here . Verifying this locally

Debug application which is run using pm2

点点圈 提交于 2019-12-03 22:16:25
Application is run by pm2 start app.js or pm2 start config.json I want to debug my application locally using node_inspector. I added debug argument pm2 start --node-args="--debug=7000" app.js It works fine but if I provide config.json instead of script app.js I don't know how to pass arguments about debug. Next piece of config doesn't work { "apps": [ { "name": "myName", "script": "app.js", "args": "['--debug=7000']" ............ } ] } So How to debug application which is run by pm2 and using config? soyuka You're almost there, use node_args instead of args : args are your script arguments