I am trying to host a discord bot on Heroku (Discord JDA, Maven). I do this by connecting to Github and then deploying. The bot 'deploys' (view attachment) but doesn't actually work (view attachment).
What could I be doing wrong, or has anyone else come across a similar issue?
Quick and dirty way to deploy it:
You'll need to setup a Procfile, extensive info on that right here: https://devcenter.heroku.com/articles/procfile
The procfile is basically a file with no extension that tells the dyno how to execute your program.
A simple
worker: java $JAVA_OPTS -jar <PATH_TO_JAR>
will work fine if you don't need more config, refer to that link for more.
You can then deploy it like this (Good to have procfile and jar on the same directory):
$ heroku deploy:jar -a <YOUR_HEROKU_APP_NAME> --jdk <JDK_VERSION> --jar <PATH_TO_JAR> -i Procfile
Then to start it just do (Assuming you want a worker dyno, which is what discord should need)
$ heroku ps:scale -a <YOUR_HEROKU_APP_NAME> worker=1
Then stop it with:
$ heroku ps:scale -a <YOUR_HEROKU_APP_NAME> worker=0
I've found this is much simpler than using git, especially if you're doing tests or simple/quick stuff.
Possible solutions:
Set up a Procfile. A Procfile basically tells Heroku what command to run when your app is deployed. Inside the Procfile, write worker: node index.js. Also, make sure Procfile has a capital "P".
Set up package.json.
npm init
Then just skip through the set up and your file should be automatically created. IMPORTANT. In your package.json file, add your node and npm versions.
node -v
npm -v
Then go an type this in your package.json.
"engines": {
node: "your-version-here"
npm: "your-version-here"
}
Then try deploying your app to Heroku again. Also, make sure you have the "nodejs" buildpack set up for your app. Run it and test the discord bot.
Related
Im trying to host my object detection api on heroku but i can't due to it not recognizing my
Procfile, which is a file and not a text file. the way its spelled is Procfile, its contents are
web:gunicorn app:app
the way i know that its the Procfile thats the problem is because when i run bash and look at the root directory of the heroku git i see Procfile but when i look at the logs i see that no web process is running and on the dashboard the dynos is completely empty.
i've tried doing
web: gunicorn app: app instead of web:gunicorn app:app
to no avail, i've made sure that gunicorn is in the requirements.txt and know that its pip installing the requirements.txt as the cmd tells me that it is when i do git push heroku master. i've tried doing echo>Procfile and then modifying the contents of the file. i've tried both echo "web:gunicorn app:app"> Procfile and echo web:gunicorn app:app>Procfile i tried doing heroku ps:scale web=1 and get Scaling web dynos... failed ! No such process type web defined in Procfile. and when i do heroku ps i get nothing
I have deployed my jar file to heroku using:
heroku deploy:jar <filename>.jar --app <appname>
Once deployed, how do I run the jar file with specific params, i.e. locally i would execute:
java -jar <filename>.jar <param1> <param2>
Am i using the Heroku service correctly? In essence I just need to run the Main command within the jar file and get the logs when completed.
Any help would be much appreciated.
heroku deploy:jar <filename>.jar --app <appname>
With this you essentially hardcorded:
jar <filename>.jar
Here is an example where you can configure parameters for your command
https://github.com/NNTin/shell-kun/tree/6b35e4b731bcf500366f60bbceafe076bf969fe1
Note: We are looking here at older software because HEAD no longer has it.
You need Procfile. app.json and the Heroku Deploy (see link in README.md) button are optional. They make deploying easier since you don't have to touch terminal/CLI.
Essentially you extend your Procfile to:
web: jar <filename>.jar $ARGS_AND_FLAGS
worker: jar <filename>.jar $ARGS_AND_FLAGS
web when you are utilizing a $PORT, worker when not.
Now you can modify your command by editing the environment variable ARGS_AND_FLAGS.
In this case the web process is activated and the worker process is deactivated.
After you changed your environment variable you can deactivate and then activate your process.
Create a Procfile in the same directory where you run heroku deploy:jar with the content:
web: java -jar <filename>.jar <param1> <param2>
and redeploy the app.
I'd like to configure a Heroku app to run a scheduled task once per day. My source tree looks like this:
bin/myScript
Procfile
package.json
When I deploy the app, I see the following error:
2017-01-11T04:31:36.660973+00:00 app[web.1]: npm ERR! missing script: start
I believe this is because Heroku tries to spin up a web dyno. I don't have a web dyno, nor do I want one. So I created a Procfile with this line:
heroku ps:scale web=0
To prevent heroku from spinning up a web dyno. That didn't work. What else can I do to prevent my app from crashing upon deployment? Does it matter if the scheduled task is going to be run in a separate one-off Dyno anyway?
You should not have the line "heroku ps:scale web=0" in your Procfile.
Doing so tells heroku to create a process type called "heroku" that attempts to run the following command on any dyno instances instantiated for it: "ps:scale web=0". That would probably generate errors, and at any rate, is not what you intended.
Instead You should run "heroku ps:scale web=0" as a Heroku toolbelt CLI command (or do the equivalent from the Resources tab of the GUI, as you already did).
I think I found a fix: in the "Resources" tab of the GUI for the web, there is a list of dynos with on/off sliders next to them. I switched the web dyno slider to off, and now when I deploy there is no crash. Still, it's unclear to me why the Procfile line was insufficient.
This is the first time I've used Heroku, and the fact that I can't find anyone in Google with a similar error to this means I'm likely doing something way wrong:
I'm following the basic Heroku setup guide here to get my NodeJS application deployed to the web. I'm deployed and trying to check my dynos with:
heroku ps:scale web=1
However, when I do this I get the error:
Scaling web dynos... failed
! No such process type web defined in Procfile.
When I run heroku ps I get nothing returned.
In my app's root directory, I have a file named Procfile (with no extension) which contains:
web: node app.js
The app runs locally without any issues (using foreman start).
Question is why is this occurring, how do I remedy it, should I even care?
Processes to be run on Heroku are defined in a simple text file called: Procfile
The Profile contains a line that defines how each of the processes in your application will run. This will be language specific and examples can be seen on the Heroku Devcenter Procfile article
Please note that the Procfile must be spelt exactly, with the first letter capitalized an all others lower case. There is no file extension for the Procfile. This Procfile should be placed in the root of your project and committed to your local git repository before doing a git push heroku master.
Should you mis-type the filename after it has been added to git, you can rename it using git with the command
git mv ProcFile Procfile
The renamed file will be staged so you can commit the changed file with the command
git commit -m "corrected name of Procfile"
I found the solution myself, from here: https://stackoverflow.com/a/7641259/556006
I had the same problem and I just now I found what was wrong. I first
accidently called the file ProcFile instead of Procfile. Simply
renaming that file did not get picked up by git. I had to do a git rm
ProcFile -f first and then add a new (correctly named) Procfile. After
that, it got pushed correctly by git and got picked up correctly by
Heroku.
I just had this issue myself, but in my case, I was missing a space between web: and the starting command in the Procfile.
For example, I had it wrong this way:
web:gunicorn run:app
Fixed it by adding a space after the colon:
web: gunicorn run:app
I am guessing you've never done git push heroku master -- that is, Heroku has never seen your code.
I'm trying to install New Relic, but it says I'll need to make changes to Procfile. I can't seem to find it at the root of the local copy of my app though. I'm using Django.
Thanks
This page on Heroku gives a lot more information on what the procfile is:
https://devcenter.heroku.com/articles/procfile
You don't have to have one to deploy to Heroku, but you can manually create one to take more control over how Heroku runs your apps. As per this excerpt from the link above:
A Procfile is not necessary to deploy apps written in most languages supported by Heroku. The platform automatically detects the language, and creates a default web process type to boot the application server.
Creating an explicit Procfile is recommended for greater control and flexibility over your app.
For Heroku to use your Procfile, add the Procfile to the root of your application push to Heroku:
$ git add .
$ git commit -m "Procfile"
$ git push heroku
...
-----> Procfile declares process types: web, worker
Compiled slug size is 10.4MB
-----> Launching... done
http://strong-stone-297.herokuapp.com deployed to Heroku
To git#heroku.com:strong-stone-297.git
* [new branch] master -> master
For New Relic support, you have to explicitly tell Heroku to run a gunicorn instance within New Relic. So your Procfile would look something like this:
newrelic-admin run-program gunicorn --workers 4 --worker-class gevent --timeout 60 mysite.wsgi
You can turn this on or off without changing your Procfile by conditionally looking for your New Relic licence in the Heroku environment variables:
Procfile:
web: bash scripts/heroku_run
scripts/heroku_run:
#!/bin/bash
run_command="gunicorn --workers 4 --worker-class gevent --timeout 60 mysite.wsgi"
# Run through New Relic monitoring if add-on installed
if [[ $NEW_RELIC_LICENSE_KEY != '' ]]; then
newrelic-admin run-program $run_command
else
$run_command
fi