[英]Hosting a runnable jar file (Discord bot) on a web server (Heroku)
I just finished creating a simple Discord bot in a runnable jar. (As a disclaimer, when it comes to the web, I'm a noob.) I was looking for a way to freely run it online and I read about all these VPS sites, but none of them offered unlimited free plans.我刚刚在可运行的 jar 中创建了一个简单的 Discord 机器人。(作为免责声明,当涉及到 web 时,我是一个菜鸟。)我正在寻找一种在线自由运行它的方法,我阅读了所有这些 VPS网站,但它们都没有提供无限制的免费计划。 So I stumbled into a site called Heroku, which allows me to run it for a good portion of the month.
所以我无意中发现了一个名为 Heroku 的网站,它让我可以在一个月的大部分时间里运行它。 I've mostly figured everything out, but there is this one error that I've been unable to fix:
我基本上已经弄清楚了所有事情,但是有一个错误我一直无法修复:
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
My Discord bot does not connect to Heroku's server and I think thats the problem, but I have no clue how to fix it.我的 Discord 机器人没有连接到 Heroku 的服务器,我认为这就是问题所在,但我不知道如何修复它。 Has anyone encountered a similar problem?
有没有人遇到过类似的问题? Am I going about hosting my bot the right way?
我是否打算以正确的方式托管我的机器人? Thanks.
谢谢。
Edit: Here is the full logs:编辑:这是完整的日志:
2016-06-11T17:00:56.792783+00:00 app[web.1]: 17:00:56.792 [main] DEBUG d.btobastian.javacord.ImplDiscordAPI - Requested gateway wss://gateway.discord.gg (token: **************************************************NdxxxW0oQ)
2016-06-11T17:00:56.765456+00:00 app[web.1]: 17:00:56.765 [main] DEBUG d.btobastian.javacord.ImplDiscordAPI - Requesting gateway (token: **************************************************NdxxxW0oQ)
2016-06-11T17:00:57.199263+00:00 app[web.1]: 17:00:57.199 [ReadingThread] DEBUG d.b.j.utils.DiscordWebsocketAdapter - Sending connect packet
2016-06-11T17:00:57.267527+00:00 app[web.1]: 17:00:57.267 [ReadingThread] DEBUG d.b.j.utils.DiscordWebsocketAdapter - Received READY-packet!
2016-06-11T17:00:57.270636+00:00 app[web.1]: 17:00:57.270 [ReadingThread] DEBUG d.b.j.utils.DiscordWebsocketAdapter - Updating status (game: none, idle: false)
2016-06-11T17:01:38.508359+00:00 app[web.1]: 17:01:38.507 [pool-2-thread-1] DEBUG d.b.j.utils.DiscordWebsocketAdapter - Sending heartbeat (interval: 41250)
2016-06-11T17:02:19.751552+00:00 app[web.1]: 17:02:19.751 [pool-2-thread-1] DEBUG d.b.j.utils.DiscordWebsocketAdapter - Sending heartbeat (interval: 41250)
2016-06-11T17:02:22.866430+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
2016-06-11T17:02:23.649874+00:00 heroku[web.1]: Process exited with status 137
So my application does not actually interact with the Heroku server and it "times out" appartently.所以我的应用程序实际上并没有与 Heroku 服务器交互,它显然“超时”。 When I run it locally, all is well, but when I upload it to a Heroku application, it "times out."
当我在本地运行它时,一切正常,但是当我将它上传到 Heroku 应用程序时,它“超时”。 I've looked for ways to bind the $PORT but been unsuccessful so far.
我一直在寻找绑定 $PORT 的方法,但到目前为止没有成功。 I've inluded it in my Procfile with no results:
我已将其包含在我的 Procfile 中但没有结果:
web: java $JAVA_OPTS -Dserver.port=$PORT -jar ideaprojects.jar --host=0.0.0.0 --port=$PORT
I've never interacted with ports before, can someone help me out?我以前从未与端口进行过交互,有人可以帮助我吗? Thanks again.
再次感谢。
Edit2: I even tried to run my bot through their "java-getting-started" by adding my Java code to the end of theirs. Edit2:我什至试图通过将我的 Java 代码添加到他们的末尾来通过他们的“java-getting-started”运行我的机器人。 Heroku doesn't crash, but it seems that my bot doesn't run either.
Heroku 没有崩溃,但我的机器人似乎也没有运行。
You are getting this error because your Procfile
configured as web .您收到此错误是因为您的
Procfile
配置为web 。 You need to configure Procfile
as worker process.您需要将
Procfile
配置为工作进程。
You can try this Procfile
configuration: worker: java -jar target/*.jar
您可以试试这个
Procfile
配置: worker: java -jar target/*.jar
Also you can to look this page: https://devcenter.heroku.com/articles/run-non-web-java-processes-on-heroku你也可以看看这个页面: https://devcenter.heroku.com/articles/run-non-web-java-processes-on-heroku
Heroku is for hosting web applications. Heroku 用于托管 web 应用程序。 It is not intended for hosting processes that aren't part of a web application you're running on Heroku, and trying to run such a process will not work well.
它不适用于托管不属于您在 Heroku 上运行的 web 应用程序的进程,并且尝试运行这样的进程将无法正常工作。
You will need a VPS to host your bot.您将需要一个 VPS 来托管您的机器人。 Yes, you have to pay for this.
是的,你必须为此付出代价。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.