How to stop Heroku from trying to start script with `npm start`?

孤者浪人 提交于 2020-01-16 12:00:07

问题


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.

Fig. 1. Screen capture of Heroku Scheduler dashboard

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

node src/spiders/clusters/auctionMacro.js

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

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.

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]: 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

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?

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

Fig 2. Complete output of $ heroku logs

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)

Edit:

Based on this SO answer, I ran the following command

heroku scale web=0

And received the following response in the terminal

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.


回答1:


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

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

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

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

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

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

Finally, deploy it back to Heroku:

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

The source of this second item is this SO answer.



来源:https://stackoverflow.com/questions/59709604/how-to-stop-heroku-from-trying-to-start-script-with-npm-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!