如何阻止Heroku尝试使用`npm start`启动脚本? [英] How to stop Heroku from trying to start script with `npm start`?

查看:98
本文介绍了如何阻止Heroku尝试使用`npm start`启动脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个基于服务器的应用程序,该应用程序在云中运行一系列自动化脚本(即机器人").我已经调配了一个Heroku Scheduler实例来自动运行这些脚本之一,如下图1所示.

I am building a server-based application that runs a series of automated scripts (i.e., "bots") in the cloud. I have provisioned an instance of Heroku Scheduler to automatically run one of those scripts as shown in the below Fig. 1.

从图1中可以看到,调度程序应该运行以下命令

As you can see from Fig. 1., the scheduler is supposed to run the following command

node src/spiders/clusters/auctionMacro.js

每十分钟一次.如图2所示,这似乎按预期发生了.它显示了完整的日志输出.

every ten minutes. Which appears to be happening as expected as shown below in Fig 2. which shows the complete log output.

从2020-01-12T10:41:54.171208 + 00:00开始的五个日志条目似乎确认了node src/spiders/clusters/auctionMacro.js的预期命令正在按预期进行并且脚本按预期执行.

The five log entries beginning at 2020-01-12T10:41:54.171208+00:00 appear to confirm the expected command of node src/spiders/clusters/auctionMacro.js is happening as expected and the script is executing as expected.

但是,以下三个日志条目表明调度程序还试图运行命令npm start并导致脚本崩溃.

However, the following three log entries indicate that the scheduler is also trying to run the command npm start and causing the script to crash.

2020-01-12T11:00:13.464651 + 00:00 heroku [web.1]:使用命令npm start启动进程
2020-01-12T11:00:15.143335 + 00:00 heroku [web.1]:状态从开始更改为崩溃
2020-01-12T11:00:15.080831 + 00:00 app [web.1]:npm错误!缺少脚本:开始

2020-01-12T11:00:13.464651+00:00 heroku[web.1]: Starting process with command npm start
2020-01-12T11:00:15.143335+00:00 heroku[web.1]: State changed from starting to crashed
2020-01-12T11:00:15.080831+00:00 app[web.1]: npm ERR! missing script: start

对此我该怎么办?我可以以某种方式关闭npm start命令吗?还是采取其他措施来纠正该问题并防止脚本崩溃?

What can I do about this? Can I turn off the npm start command somehow? Or do something else to correct the issue and prevent the script from crashing?

heroku logs生成的完整日志输出如下.

The full log output generated by heroku logs is as follows.

2020-01-12T10:41:46.690564 + 00:00 app [api]:用户scheduler@addons.heroku.com使用命令node src/spiders/clusters/auctionMacro.js启动进程
2020-01-12T10:41:54.171208 + 00:00 heroku [scheduler.2053]:使用命令node src/spiders/clusters/auctionMacro.js启动进程
2020-01-12T10:41:54.864597 + 00:00 heroku [scheduler.2053]:状态从开始更改为开始
2020-01-12T10:41:56.797007 + 00:00 app [scheduler.2053]:[成功的脚本日志]
2020-01-12T10:41:56.799138 + 00:00 app [scheduler.2053]:[成功的脚本日志]
2020-01-12T10:41:56.799853 + 00:00 app [scheduler.2053]:[成功的脚本日志]
2020-01-12T10:41:56.893782 + 00:00 app [scheduler.2053]:[成功的脚本日志]
2020-01-12T10:41:59.126489 + 00:00 heroku [scheduler.2053]:状态从完成更改为完成
2020-01-12T10:41:59.111484 + 00:00 heroku [scheduler.2053]:进程退出,状态为0
2020-01-12T10:49:21.119405 + 00:00 app [api]:用户myemail@example.com使用命令node src/spiders/clusters/auctionMacro.js启动进程
2020-01-12T10:49:29.862904 + 00:00 heroku [run.9372]:状态从开始更改为开始
2020-01-12T10:49:29.827990 + 00:00 heroku [run.9372]:正在等待客户端
2020-01-12T10:49:29.878338 + 00:00 heroku [run.9372]:使用命令node src/spiders/clusters/auctionMacro.js启动进程
2020-01-12T11:00:05.438362 + 00:00 heroku [web.1]:状态从崩溃更改为开始
2020-01-12T11:00:13.464651 + 00:00 heroku [web.1]:使用命令npm start启动进程
2020-01-12T11:00:15.143335 + 00:00 heroku [web.1]:状态从开始更改为崩溃
2020-01-12T11:00:15.080831 + 00:00 app [web.1]:npm错误!缺少脚本:开始
2020-01-12T11:00:15.088306 + 00:00 app [web.1]:
2020-01-12T11:00:15.088587 + 00:00 app [web.1]:npm错误!可以在以下位置找到此运行的完整日志:
2020-01-12T11:00:15.088690 + 00:00 app [web.1]:npm错误! /app/.npm/_logs/2020-01-12T11_00_15_081Z-debug.log
2020-01-12T11:00:15.130770 + 00:00 heroku [web.1]:进程退出,状态为1
2020-01-12T11:08:51.893315 + 00:00 heroku [run.9372]:客户端连接已关闭.将SIGHUP发送到所有进程
2020-01-12T11:08:52.437813 + 00:00 heroku [run.9372]:状态从向上更改为完整
2020-01-12T11:08:52.421870 + 00:00 heroku [run.9372]:进程退出,状态为129
me @ My-MacBook-Air手偶%heroku维护
2020-01-12T22:15:01.428118 + 00:00 app [scheduler.9940]:==开始:2020-01-12 22:04:21.402
2020-01-12T22:15:01.428167 + 00:00 app [scheduler.9940]:
2020-01-12T22:15:02.410217 + 00:00 heroku [scheduler.9940]:使用SIGTERM停止所有进程
2020-01-12T22:15:02.481455 + 00:00 heroku [scheduler.9940]:进程退出,状态为143.929(运行10.7分钟)

2020-01-12T10:41:46.690564+00:00 app[api]: Starting process with command node src/spiders/clusters/auctionMacro.js by user scheduler@addons.heroku.com
2020-01-12T10:41:54.171208+00:00 heroku[scheduler.2053]: Starting process with command node src/spiders/clusters/auctionMacro.js
2020-01-12T10:41:54.864597+00:00 heroku[scheduler.2053]: State changed from starting to up
2020-01-12T10:41:56.797007+00:00 app[scheduler.2053]: [Successful script log]
2020-01-12T10:41:56.799138+00:00 app[scheduler.2053]: [Successful script log]
2020-01-12T10:41:56.799853+00:00 app[scheduler.2053]: [Successful script log]
2020-01-12T10:41:56.893782+00:00 app[scheduler.2053]: [Successful script log]
2020-01-12T10:41:59.126489+00:00 heroku[scheduler.2053]: State changed from up to complete
2020-01-12T10:41:59.111484+00:00 heroku[scheduler.2053]: Process exited with status 0
2020-01-12T10:49:21.119405+00:00 app[api]: Starting process with command node src/spiders/clusters/auctionMacro.js by user myemail@example.com
2020-01-12T10:49:29.862904+00:00 heroku[run.9372]: State changed from starting to up
2020-01-12T10:49:29.827990+00:00 heroku[run.9372]: Awaiting client
2020-01-12T10:49:29.878338+00:00 heroku[run.9372]: Starting process with command node src/spiders/clusters/auctionMacro.js
2020-01-12T11:00:05.438362+00:00 heroku[web.1]: State changed from crashed to starting
2020-01-12T11:00:13.464651+00:00 heroku[web.1]: Starting process with command npm start
2020-01-12T11:00:15.143335+00:00 heroku[web.1]: State changed from starting to crashed
2020-01-12T11:00:15.080831+00:00 app[web.1]: npm ERR! missing script: start
2020-01-12T11:00:15.088306+00:00 app[web.1]:
2020-01-12T11:00:15.088587+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-01-12T11:00:15.088690+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-01-12T11_00_15_081Z-debug.log
2020-01-12T11:00:15.130770+00:00 heroku[web.1]: Process exited with status 1
2020-01-12T11:08:51.893315+00:00 heroku[run.9372]: Client connection closed. Sending SIGHUP to all processes
2020-01-12T11:08:52.437813+00:00 heroku[run.9372]: State changed from up to complete
2020-01-12T11:08:52.421870+00:00 heroku[run.9372]: Process exited with status 129
me@My-MacBook-Air puppeteer % heroku maint
2020-01-12T22:15:01.428118+00:00 app[scheduler.9940]: == Start: 2020-01-12 22:04:21.402
2020-01-12T22:15:01.428167+00:00 app[scheduler.9940]:
2020-01-12T22:15:02.410217+00:00 heroku[scheduler.9940]: Stopping all processes with SIGTERM
2020-01-12T22:15:02.481455+00:00 heroku[scheduler.9940]: Process exited with status 143.929 (running for 10.7 minutes)

基于此SO答案,我运行了以下命令

heroku scale web=0

并在终端中收到以下响应

And received the following response in the terminal

缩放动态...完成,现在以0:免费运行网络

Scaling dynos... done, now running web at 0:Free

我不确定这是什么意思,或者这是我应该前进的方向.

I'm not sure what that means or if this is the direction I should be heading.

推荐答案

对我来说,解决方案有两个部分.实施了这两个部分后,我解决了这个问题.

The solution had two parts for me. I solved the problem after implementing both parts.

首先,我必须使用以下终端命令关闭npm start,如对OP进行的编辑所示.

Firstly, I had to turn off the npm start with the following terminal command as indicated in the edit to the OP.

heroku scale web=0

第二,我必须配置我的buildpacks和puppeteer.launch()选项以支持在Heroku服务器环境中运行,如下所示.

Secondly, I had to configure my buildpacks and puppeteer.launch() options to support running in the Heroku server environment as follows.

首先,我清除所有构建包,然后添加puppeteer-heroku-buildpack和heroku/nodejs一个:

First, I clear all my buildpacks and then I added the puppeteer-heroku-buildpack and the heroku/nodejs one:

$ heroku buildpacks:clear
$ heroku buildpacks:add --index 1 https://github.com/jontewks/puppeteer-heroku-buildpack
$ heroku buildpacks:add --index 1 heroku/nodejs

然后,将以下args添加到操纵up的启动函数中:

Then, add the following args to the puppeteer launch function:

const browser = await puppeteer.launch({
  args : [
    '--no-sandbox',
    '--disable-setuid-sandbox',
  ],
});

最后,将其部署回Heroku:

Finally, deploy it back to Heroku:

$ git add .
$ git commit -m "Fixing deployment issue"
$ git push heroku master

第二项的来源是该SO答案.

这篇关于如何阻止Heroku尝试使用`npm start`启动脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆