Jruby on Rails not deploying to Heroku? - ruby-on-rails

I've spent hours unsuccessfully trying to deploy my app to Heroku, and can't figure out the problem. I'm running on Windows and using JDK8 Jruby9.0.0.0. I set up using the instructions found here and deploy a new app using this tutorial. The exact commands I'm using are:
C:\Users\MyName>Jruby -S rails new MyApp
---
C:\Users\MyName>cd MyApp
---
C:\Users\MyName\MyApp>git init
---
C:\Users\MyName\MyApp>git add .
---
C:\Users\MyName\MyApp>git commit -m "my first commit"
---
C:\Users\MyName\MyApp>heroku create
---
C:\Users\MyName\MyApp>git push heroku master
---
C:\Users\MyName\MyApp>heroku open
Unfortunately this provides the following "Applicaton Error" when I try to open the app:
2015-11-04T19:28:36.377052+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 27765 -e production`
2015-11-04T19:28:38.105808+00:00 app[web.1]: /usr/bin/env: jruby.exe: No such file or directory
2015-11-04T19:28:38.976959+00:00 heroku[web.1]: Process exited with status 127
2015-11-04T19:28:38.994372+00:00 heroku[web.1]: State changed from starting to crashed
2015-11-04T19:28:38.995406+00:00 heroku[web.1]: State changed from crashed to starting
2015-11-04T19:28:40.545185+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 14126 -e production`
2015-11-04T19:28:41.946326+00:00 app[web.1]: /usr/bin/env: jruby.exe: No such file or directory
2015-11-04T19:28:42.503828+00:00 heroku[web.1]: State changed from starting to crashed
2015-11-04T19:28:42.496390+00:00 heroku[web.1]: Process exited with status 127
2015-11-04T19:28:43.384581+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=desolate-lake-2856.herokuapp.com request_id=7d58e322-072a-4e26-bfdf-53ff637ebe97 fwd="86.174.222.227" dyno= connect= service= status=503 bytes=
2015-11-04T19:28:43.638575+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=desolate-lake-2856.herokuapp.com request_id=af171d45-f0ce-4e2e-a0ba-1375cfb90601 fwd="86.174.222.227" dyno= connect= service= status=503 bytes=
2015-11-04T19:28:44.199636+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=desolate-lake-2856.herokuapp.com request_id=b0e25fc6-0497-4a6b-ac71-fde22c700e57 fwd="86.174.222.227" dyno= connect= service= status=503 bytes=
2015-11-04T19:28:44.922656+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=desolate-lake-2856.herokuapp.com request_id=d680200e-e6e2-4132-92fe-fcddf8df77f4 fwd="104.131.28.255" dyno= connect= service= status=503 bytes=
I've followed instructions found on SO which suggest renaming bin/bundle,rails,rake to remove the '.exe', but this does not work.
Any ideas on what is going wrong here? Thanks!
EDIT:
I should have said that the app cloned in the Heroku tutorial deploys to Heroku as it should, but unfortunately it is completely different in structure to the app created by the CMD command 'Jruby -S rails new MyApp'. The cloned app has no 'bin' directory, and the 'Jruby -S new' app has no procfile. I think this means that the problem lies with how the 'Jruby -S new' app is configured to deploy, i.e. I need to specify how the process should start? Both apps work locally.
I know I could clone the heroku app every time I create a new rails app, but this seems like a bit of a clunky work around!

It looks like you may have your bin/rails script checked into Git. And if that script was generated on Windows, I think it will have jruby.exe in it. Make sure you remove those files by running:
> git rm -rf bin
And then add bin/ to your `.gitignore to make sure it doesn't get back in. Then finally:
> git commit -am "remove bin scripts"
> git push heroku master

Related

Active Storage causing Rails app to fail on Heroku; works locally

I have a Rails app that works fine locally. It does not require any database. I am trying to deploy it using Heroku, but this is the only information I am getting in my logs as to why it's not working:
2018-09-14T17:27:28.074554+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=calendarizer.herokuapp.com request_id=4da3eec1-23dd-4d1a-ae8f-7b05086d20fc fwd="65.207.79.74" dyno= connect= service= status=503 bytes= protocol=https
2018-09-14T17:27:28.469113+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=calendarizer.herokuapp.com request_id=f079f20e-a9c1-4547-b563-3c2822b89e2d fwd="65.207.79.74" dyno= connect= service= status=503 bytes= protocol=https
My log level is set to DEBUG. No idea where else to look or how to tackle this problem.
EDIT:
I went back in the logs and I found this:
2018-09-14T17:37:19.872142+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.2.1/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined method `has_one_attached' for #<Class:0x00000007a055f8> (NoMethodError)
I had not heard of ActiveStorage before now, but it's not something I'm using (at least not intentionally).
Log dump:
2018-09-14T17:46:41.000000+00:00 app[api]: Build started by user username#gmail.com
2018-09-14T17:46:59.000000+00:00 app[api]: Build failed -- check your build logs
2018-09-14T17:47:09.445004+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=calendarizer.herokuapp.com request_id=6dca7f6f-3afd-4bcd-b144-f63b85994472 fwd="65.207.79.74" dyno= connect= service= status=503 bytes= protocol=https
2018-09-14T17:47:09.792706+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=calendarizer.herokuapp.com request_id=1818345c-2dfb-4a30-ada6-65ca3bbc04ea fwd="65.207.79.74" dyno= connect= service= status=503 bytes= protocol=https
2018-09-14T17:56:48.278447+00:00 app[api]: Starting process with command `bundle exec rake db:migrate` by user username#gmail.com
2018-09-14T17:56:52.733021+00:00 heroku[run.7080]: Awaiting client
2018-09-14T17:56:52.763164+00:00 heroku[run.7080]: Starting process with command `bundle exec rake db:migrate`
2018-09-14T17:56:52.907308+00:00 heroku[run.7080]: State changed from starting to up
2018-09-14T17:57:00.092474+00:00 heroku[run.7080]: Process exited with status 1
2018-09-14T17:57:00.107737+00:00 heroku[run.7080]: State changed from up to complete
2018-09-14T17:58:27.000000+00:00 app[api]: Build started by user username#gmail.com
2018-09-14T17:58:40.000000+00:00 app[api]: Build failed -- check your build logs
2018-09-14T17:59:08.348804+00:00 app[api]: Starting process with command `bundle exec rake db:migrate` by user username#gmail.com
2018-09-14T17:59:14.334567+00:00 heroku[run.7746]: State changed from starting to up
2018-09-14T17:59:14.252562+00:00 heroku[run.7746]: Awaiting client
2018-09-14T17:59:14.278462+00:00 heroku[run.7746]: Starting process with command `bundle exec rake db:migrate`
2018-09-14T17:59:22.174620+00:00 heroku[run.7746]: Process exited with status 1
2018-09-14T17:59:22.189708+00:00 heroku[run.7746]: State changed from up to complete
2018-09-14T17:59:56.283122+00:00 app[api]: Starting process with command `bundle exec rake db:migrate` by user username#gmail.com
2018-09-14T18:00:05.530380+00:00 heroku[run.7894]: State changed from starting to up
2018-09-14T18:00:05.579669+00:00 heroku[run.7894]: Awaiting client
2018-09-14T18:00:05.633999+00:00 heroku[run.7894]: Starting process with command `bundle exec rake db:migrate`
2018-09-14T18:00:20.779574+00:00 heroku[run.7894]: State changed from up to complete
2018-09-14T18:00:20.763154+00:00 heroku[run.7894]: Process exited with status 1
2018-09-14T18:01:58.718055+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=calendarizer.herokuapp.com request_id=989475e7-affc-41a2-ade6-5cf21ce746a9 fwd="65.207.79.74" dyno= connect= service= status=503 bytes= protocol=https
2018-09-14T18:01:59.041312+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=calendarizer.herokuapp.com request_id=38c77377-2758-4a31-9219-6dcb548a5b1e fwd="65.207.79.74" dyno= connect= service= status=503 bytes= protocol=https
Heroku usually wants to see some kind of database (ie pg) to run if something is going to get saved, which I believe having ActiveRecord in your app is going to imply (even if you don't intend to use it). So you have two solutions I believe. In your dev & test environment you likely have sqlite3 as your database (you can look in your gemfile), but Heroku doesn't work with sqlite3.
Option 1:
Disable ActiveRecord in your app - Following this post: Disable Active Storage in Rails 5.2
Option 2:
Add a database to your production environment for heroku, so it's happy:
- in your gemfile see if you have a production group already
group :production do
if not add it
add in the pg gem:
gem 'pg'
So you should end up with something like this in your gemfile:
group :production do
gem 'pg'
end
Then commit and push to Heroku. You may need to restart the Dynos in Heroku, and you may need to create the database files on heroku too:
heroku run rails db:create
You should be up and running now.
For me the problem was that the adapter in database.yml was sqlite3.
So I changed the production section of config/database.yml to:
production:
adapter: postgresql
encoding: unicodeubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
database: myapp_production
username: myapp
password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>

Getting Heroku h10 error when it works locally

Currently I am getting a h10 app crashed error even though it works locally and the logs do not seem very helpful. The log first has the error
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within
60 seconds of launch before getting the error at=error code=H10
desc="App crashed" method=GET path="/favicon.ico"
host=maitri-compassionate-care-app.herokuapp.com
request_id=602ed7f2-118f-43b2-b57f-077b89c7b2c4 fwd="98.248.251.49"
dyno= connect= service= status=503 bytes=
Here is the log:
2016-04-29T01:44:39.917289+00:00 heroku[slug-compiler]: Slug compilation started
2016-04-29T01:44:39.917299+00:00 heroku[slug-compiler]: Slug compilation finished
2016-04-29T01:44:41.023311+00:00 heroku[web.1]: State changed from crashed to starting
2016-04-29T01:44:43.205739+00:00 heroku[web.1]: Starting process with command `bundle exec rails s`
2016-04-29T01:44:46.498256+00:00 app[web.1]: DEPRECATION WARNING: The configuration option `config.serve_static_assets` has been renamed to `config.serve_static_files` to clarify its role (it merely enables serving everything in the `public` folder and is unrelated to the asset pipeline). The `serve_static_assets` alias will be removed in Rails 5.0. Please migrate your configuration files accordingly. (called from block in <top (required)> at /app/config/environments/production.rb:2)
2016-04-29T01:44:46.880147+00:00 app[web.1]: [2016-04-29 01:44:46] INFO WEBrick 1.3.1
2016-04-29T01:44:46.880438+00:00 app[web.1]: [2016-04-29 01:44:46] INFO WEBrick::HTTPServer#start: pid=3 port=3000
2016-04-29T01:44:46.880180+00:00 app[web.1]: [2016-04-29 01:44:46] INFO ruby 2.2.2 (2015-04-13) [x86_64-linux]
2016-04-29T01:45:43.548293+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-04-29T01:45:43.548293+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-04-29T01:45:44.291920+00:00 heroku[web.1]: Process exited with status 137
2016-04-29T01:45:44.312346+00:00 heroku[web.1]: State changed from starting to crashed
2016-04-29T01:45:48.319822+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=maitri-compassionate-care-app.herokuapp.com request_id=242958be-0403-4b41-aec9-c2d1603630a2 fwd="98.248.251.49" dyno= connect= service= status=503 bytes=
2016-04-29T01:45:48.178954+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=maitri-compassionate-care-app.herokuapp.com request_id=ae7f2a3a-d65e-4829-84b6-74c178e2973d fwd="98.248.251.49" dyno= connect= service= status=503 bytes=
2016-04-29T01:45:49.055039+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=maitri-compassionate-care-app.herokuapp.com request_id=602ed7f2-118f-43b2-b57f-077b89c7b2c4 fwd="98.248.251.49" dyno= connect= service= status=503 bytes=
I have tried heroku restart, heroku ps restart, and rake rails update bin but none of them seem to help. I am not sure how to get a more specific error besides just a timeout and a crash.
Thanks
It looks like your app is using WEBrick as the web server. This is fine for a local development environment, but it shouldn't be used in a production environment such as when deployed to Heroku.
Heroku recommends using puma as the production server. Detailed instructions can be found in their dev center documentation.
https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server
From Heroku docs:
In the Common Runtime, a web dyno must bind to its assigned $PORT within 60 seconds of startup. If it doesn’t, it is terminated by the dyno manager and a R10 Boot Timeout error is logged. Processes can bind to other ports before and after binding to $PORT.
According to your logs, WEBrick is running on port 3000 instead of $PORT, leaving $PORT unbound to trip the 60-second timeout. WEBrick must be configured to start on the Heroku-assigned port $PORT. You can do that with a Procfile.
Create a Procfile, named exactly that, with the following line:
web: bundle exec rails server -p $PORT
Then (from the docs):
For Heroku to use your Procfile, add the Procfile to the root directory of your application, then push to Heroku:
$ git add .
$ git commit -m "Procfile"
$ git push heroku

Heroku database error? Cannot Rake db:migrate

I've been stuck on this for hours. I've been going back and forth with rollbacks and heroku has been crashing on me. The error I've been getting is Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.
If you are the application owner, check your logs for details.
I've tried heroku pg:reset DATABASE_URL and then heroku rake db:migrate many many many times and it still prompts that error each time.
Here are my logs
2015-08-20T03:53:52.883786+00:00 heroku[run.7282]: Awaiting client
2015-08-20T03:53:52.917990+00:00 heroku[run.7282]: Starting process with command `bundle exec rake db:migrate`
2015-08-20T03:53:53.287377+00:00 heroku[run.7282]: State changed from starting to up
2015-08-20T03:53:58.412740+00:00 heroku[run.7282]: Process exited with status 0
2015-08-20T03:53:58.432909+00:00 heroku[run.7282]: State changed from up to complete
2015-08-20T03:54:04.586682+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=linkmony.herokuapp.com request_id=f90ecec2-49f5-4faa-9736-40bdeb637b5e fwd="76.103.13.109" dyno= connect= service= status=503 bytes=
2015-08-20T03:54:05.400560+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=linkmony.herokuapp.com request_id=44fb2fae-15b8-4359-bbbb-47c59b2a7d3b fwd="76.103.12.101" dyno= connect= service= status=503 bytes=
Running the following in terminal should give you more info:
$ heroku run rails console
(hat tip: ntimba20)

heroku run rake db:migrate error for rails and mysql project

i have a project with rails 4.2 and mysql database. but when i do heroku run rake db:migrate result is:
Running `rake db:migrate` attached to terminal... up, run.1461
/usr/bin/env: ruby2.2: No such file or directory
and i don't have bin in my .gitignore.
in my heroku logs i have two errors:
heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=serene-ocean-1351.herokuapp.com request_id=a40f485d-e55e-4246-b863-a8b13a3b89fa fwd="199.189.106.136" dyno= connect= service= status=503 bytes=
heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=serene-ocean-1351.herokuapp.com request_id=3404e956-71db-4530-be1f-ce6f3f23a857 fwd="199.189.106.136" dyno= connect= service= status=503 bytes=
Look up files in the bin directory of the project, in the first line will be
#!/usr/bin/env ruby2.2
you have to simply change it to
#!/usr/bin/env ruby
If you have just upgraded to Rails 4 then try the following to update Heroku's binaries to support your commands.
$ heroku run rake rails:update:bin --app serene-ocean-1351

One Month Rails - Going Online With Heroku - Application Error

I have reached the "Going Online With Heroku" section of One Month Rails.
After following the steps
` Pudge#PUDGE-PC ~/desktop/pinteresting (master)
$ heroku keys:add
Found the following SSH public keys:
1) github_rsa.pub
2) id_rsa.pub
Which would you like to use with your Heroku account? 2
Uploading SSH public key C:/Users/Pudge/.ssh/id_rsa.pub... done
Pudge#PUDGE-PC ~/desktop/pinteresting (master)
$ heroku create
Creating evening-oasis-5199... done, stack is cedar
http://evening-oasis-5199.herokuapp.com/ | git#heroku.com:evening-oasis-5199.git
Git remote heroku added`
I open the app at the given location and it comes back with "Application Error"
`←[36m2014-03-11T00:16:24.525751+00:00 heroku[api]:←[0m Enable Logplex by chitrad
er84#gmail.com
←[36m2014-03-11T00:16:24.525824+00:00 heroku[api]:←[0m Release v2 created by chi
trader84#gmail.com
←[33m2014-03-11T00:16:38.664429+00:00 heroku[router]:←[0m at=error code=H14 desc
="No web processes running" method=GET path=/ host=evening-oasis-5199.herokuapp.
com request_id=8229c76f-de74-43d6-ac14-fa3ecefe8ff6 fwd="99.9.45.163" dyno= conn
ect= service= status=503 bytes=
←[33m2014-03-11T00:26:09.486092+00:00 heroku[router]:←[0m at=error code=H14 desc
="No web processes running" method=GET path=/ host=evening-oasis-5199.herokuapp.
com request_id=afba73c5-ad0d-41a2-8d0c-9faf75dc4e0b fwd="99.9.45.163" dyno= conn
ect= service= status=503 bytes=
←[33m2014-03-11T00:26:09.717414+00:00 heroku[router]:←[0m at=error code=H14 desc
="No web processes running" method=GET path=/favicon.ico host=evening-oasis-5199
.herokuapp.com request_id=4c3f6b80-1f0a-42d5-80f6-3510b093872b fwd="99.9.45.163"
dyno= connect= service= status=503 bytes=
←[33m2014-03-11T00:28:09.983774+00:00 heroku[router]:←[0m at=error code=H14 desc
="No web processes running" method=GET path=/ host=evening-oasis-5199.herokuapp.
com request_id=21b356bb-cbcb-4489-82e5-6e6d0c69dfd5 fwd="99.9.45.163" dyno= conn
ect= service= status=503 bytes=
←[33m2014-03-11T00:28:10.239213+00:00 heroku[router]:←[0m at=error code=H14 desc
="No web processes running" method=GET path=/favicon.ico host=evening-oasis-5199
.herokuapp.com request_id=fcf0e24d-f9f6-42a5-b382-841ed9704e1e fwd="99.9.45.163"
dyno= connect= service= status=503 bytes=
←[32m2014-03-11T03:15:10+00:00 heroku[slug-compiler]:←[0m Slug compilation start
ed
←[32m2014-03-11T03:15:32+00:00 heroku[slug-compiler]:←[0m Slug compilation faile
d: failed to compile Ruby app
←[36m2014-03-11T03:15:57.572557+00:00 heroku[api]:←[0m Starting process with com
mand `rake db:migrate` by chitrader84#gmail.com
←[35m2014-03-11T03:15:59.264402+00:00 heroku[run.1396]:←[0m Starting process wit
h command `rake db:migrate`
←[35m2014-03-11T03:15:59.226632+00:00 heroku[run.1396]:←[0m Awaiting client
←[35m2014-03-11T03:15:59.359699+00:00 heroku[run.1396]:←[0m State changed from s
tarting to up
←[35m2014-03-11T03:16:01.043376+00:00 heroku[run.1396]:←[0m State changed from u
p to complete
←[35m2014-03-11T03:16:01.037656+00:00 heroku[run.1396]:←[0m Process exited with
status 1
←[33m2014-03-11T03:16:10.744992+00:00 heroku[router]:←[0m at=error code=H14 desc
="No web processes running" method=GET path=/favicon.ico host=evening-oasis-5199
.herokuapp.com request_id=add463f3-a0ad-4682-aa06-b0e7649481a3 fwd="99.9.45.163"
dyno= connect= service= status=503 bytes=
Here is what my log says.
So I just did a quick creation to test.
I did
step1:
rails new testapp
cd testapp
git add .
git commit -m 'initial commit'
heroku create
at this point, i did
heroku open
and I get the same application error with the same "No web processes running"
My feeling is you stopped here and not pushed your initial commit
You would need to run this additionally:
git push heroku master
heroku run rake db:migrate <--- only needed if you have migrations
heroku open
The error log says "No web processes running".
So how about running one?
Try this
heroku ps:scale web=1

Resources