简体   繁体   English

使我的JAVA(jar)程序在Heroku上运行

[英]Keeping my JAVA (jar) program running on Heroku

I have made a bot in Java and it works great when I run the command: 我已经用Java制作了一个机器人,当我运行命令时,它的运行效果很好:

heroku run nohup java -jar bot.jar

However, after 24h Heroku closes it because of their Dyno policy. 但是,由于他们的Dyno政策,Heroku在24小时后将其关闭。 So, I thought of making a Procfile in order for it to execute the command above everytime it comes alive again. 因此,我想到要制作一个Procfile ,以便它每次再次运行时都能执行上面的命令。

I've tried placing the following commands inside the Procfile : 我尝试将以下命令放入Procfile中

worker: java -jar bot.jar
worker: nohup java -jar bot.jar

And I even made a run.sh file that contains: 我什至制作了一个run.sh文件,其中包含:

#!/bin/bash
nohup java -jar bot.jar

In order to make a Procfile that has: 为了制作具有以下内容的Procfile

worker: sh run.sh

Sadly, none of this works, because everytime the Dyno executes the Procfile (right after I push a new version of it through git), the bot never comes alive. 可悲的是,这些都不起作用 ,因为Dyno每次执行Procfile时 (就在我通过git推送新版本后),该bot都不会存活。 The logs show: 日志显示:

2017-06-07T13:17:33.651806+00:00 app[api]: Starting process with command `sh run.sh` by XXXX

2017-06-07T13:17:37.958327+00:00 heroku[run.2087]: State changed from starting to up

2017-06-07T13:17:37.948696+00:00 heroku[run.2087]: Awaiting client

2017-06-07T13:17:38.283581+00:00 heroku[run.2087]: Starting process with command `sh run.sh`

2017-06-07T13:17:52.807189+00:00 heroku[run.2087]: Client connection closed. Sending SIGHUP to all processes

2017-06-07T13:17:53.343009+00:00 heroku[run.2087]: Process exited with status 129

2017-06-07T13:17:53.359331+00:00 heroku[run.2087]: State changed from up to complete

2017-06-07T13:24:32.000000+00:00 app[api]: Build started by user XXXX

2017-06-07T13:24:43.090567+00:00 app[api]: Deploy YYYY by user XXXX

2017-06-07T13:24:43.090567+00:00 app[api]: Release v17 created by user XXXX

2017-06-07T13:24:32.000000+00:00 app[api]: Build succeeded

I have no idea what to do in order for my bot to run from the Procfile . 我不知道该怎么做才能使我的机器人从Procfile运行。 Can you help me? 你能帮助我吗?

Thanks. 谢谢。

Try running: 尝试运行:

$ heroku ps:scale worker=1

This will ensure that one worker process is always running. 这将确保一个工作进程始终在运行。

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

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