简体   繁体   English

使用 PM2 运行自定义 npm 脚本

[英]Run a custom npm script with PM2

I am currently developing several Telegram bots but I want to keep all of them in the same git repository.我目前正在开发几个 Telegram 机器人,但我想将它们全部保存在同一个 git 存储库中。 The issue is that on the other hand, I want to run them as separate processes.问题是,另一方面,我想将它们作为单独的进程运行。

Since I'm using the Telegraf framework, to run a bot it goes such as: micro-bot src/bot-one/bot.js由于我使用的是 Telegraf 框架,因此要运行一个机器人,例如: micro-bot src/bot-one/bot.js

The problem comes when doing this with PM2.使用 PM2 执行此操作时会出现问题。 I've been able to run one of the bots with the npm start script like this:我已经能够使用npm start脚本运行其中一个机器人,如下所示:

pm2 start --name "WeatherBot" npm -- start -- -t <
TOKEN>

But I'd like to be able to create custom scripts like this:但我希望能够创建这样的自定义脚本:

"main": "src/weatherWarnBot/bot.js",
"scripts": {
    "start": "micro-bot",
    "littleAppleBot": "micro-bot src/littleAppleBot/bot.js",
    "weatherWarnBot": "micro-bot src/weatherWarnBot/bot.js"
}

But, how would the PM2 command be to run each of the two custom scripts?但是,PM2 命令将如何运行这两个自定义脚本中的每一个? I was thinking of having the bot tokens set as enviroment variables of the system, for simplification.为了简化,我正在考虑将机器人令牌设置为系统的环境变量。

试试这个:

pm2 start npm -- run littleAppleBot --

pm2 start npm -- run weatherWarnBot --

使用这个:-

pm2 start --name "Script Name" npm -- run <YOUR CUSTOM SCRIPT> --

pm2 start npm --name "你的应用名称" -- start

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM