Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having issues getting a war file to run #487

Open
hmistry opened this issue Dec 16, 2020 · 4 comments
Open

Having issues getting a war file to run #487

hmistry opened this issue Dec 16, 2020 · 4 comments

Comments

@hmistry
Copy link

hmistry commented Dec 16, 2020

I created a simple test Rails app with sqlite db and used warbler to create a compiled executable war file. I used java -server -jar app.war -S puma -p 3000 -c config/puma.rb to start the app. I also tried with -S rails s but no luck. It says either "config.ru not found" or "no application configured, nothing to run" or some other errors and exit system. Googling did not yield much, a few articles from 2012-14, and a couple recent but wasn't helpful.

Could you help guide on how to get create a compiled rails application? Let's start with:

  1. Is it better to create a runnable or executable war or jar file of the Rails app?
  2. Can I use puma as the jruby server or something else? I saw one article using puma.
  3. What do you recommend on how to handle filling in values for database.yml and other such configuration files when doing production deployments of the compiled war app? Env vars?
  4. How would I run rails db:setup and rails db:migrate to setup production databases using the compiled war app?
  5. Lastly is there any examples of a working rails production app that I can refer to on how they configure warbler to create war file and run?

Using Rails 6.0.3.4, latest JRuby 9.2.13 for simple test app but the target app will be rails 5.1.7.

Thank you in advance.

@headius
Copy link
Member

headius commented Dec 17, 2020

Could you show us the commands you used to build the war file?

It sounds like it is getting built but upon booting up it can't find the files inside the war. Perhaps the way those files get loaded no longer works in a jar/war form.

@hmistry
Copy link
Author

hmistry commented Dec 17, 2020

Sure. Thank you for your quick response. Really need to get this working soon.

I created warble.rb and set compiled runnable options. Every thing else is default values. I had issues with executable option trying to download jetty and failed with socketError to repo2.maven.org - name or service not known.

The sample rails app works when I run bundle exec rails s so I know the app is working with puma.

# Create war file
USHQMC5705:jrbin hirenm$ bundle exec warble war
java -classpath "/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/jruby-jars-9.2.13.0/lib/jruby-core-9.2.13.0-complete.jar":"/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/jruby-jars-9.2.13.0/lib/jruby-stdlib-9.2.13.0.jar":"/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/jruby-rack-1.1.21/lib/jruby-rack-1.1.21.jar"  org.jruby.Main -S jrubyc  "app/controllers/application_controller.rb" "app/controllers/cars_controller.rb" "app/helpers/application_helper.rb" "app/helpers/cars_helper.rb" "app/jobs/application_job.rb" "app/mailers/application_mailer.rb" "app/models/application_record.rb" "app/models/car.rb" "db/migrate/20201202235834_create_cars.rb" "db/schema.rb" "db/seeds.rb" "config/application.rb" "config/boot.rb" "config/environment.rb" "config/environments/development.rb" "config/environments/production.rb" "config/environments/test.rb" "config/initializers/application_controller_renderer.rb" "config/initializers/assets.rb" "config/initializers/backtrace_silencers.rb" "config/initializers/content_security_policy.rb" "config/initializers/cookies_serializer.rb" "config/initializers/filter_parameter_logging.rb" "config/initializers/inflections.rb" "config/initializers/mime_types.rb" "config/initializers/wrap_parameters.rb" "config/puma.rb" "config/routes.rb" "config/warble.rb"
rm -f jrbin.war
Creating jrbin.war
rm -f app/controllers/application_controller.class app/controllers/cars_controller.class app/helpers/application_helper.class app/helpers/cars_helper.class app/jobs/application_job.class app/mailers/application_mailer.class app/models/application_record.class app/models/car.class db/migrate/20201202235834_create_cars.class db/schema.class db/seeds.class config/application.class config/boot.class config/environment.class config/environments/development.class config/environments/production.class config/environments/test.class config/initializers/application_controller_renderer.class config/initializers/assets.class config/initializers/backtrace_silencers.class config/initializers/content_security_policy.class config/initializers/cookies_serializer.class config/initializers/filter_parameter_logging.class config/initializers/inflections.class config/initializers/mime_types.class config/initializers/wrap_parameters.class config/puma.class config/routes.class config/warble.class

# move war file to separate directory
USHQMC5705:jrtest hirenm$ cp jrbin/jrbin.war war/
USHQMC5705:war hirenm$ ls
jrbin.war

# run war file with puma, setup + migrate db, run war file again -> no success
USHQMC5705:war hirenm$ RAILS_ENV=production java -server -jar jrbin.war -S puma -t 5:5 -p 3000 -c config/puma.rb
ERROR: org.jruby.exceptions.RuntimeError: (AmbiguousOption) ambiguous option: -c
USHQMC5705:war hirenm$ RAILS_ENV=production java -server -jar jrbin.war -S rails db:create
Created database 'db/production.sqlite3'
USHQMC5705:war hirenm$ RAILS_ENV=production java -server -jar jrbin.war -S rails db:migrate
== 20201202235834 CreateCars: migrating =======================================
-- create_table(:cars)
   -> 0.0066s
   -> 0 rows
== 20201202235834 CreateCars: migrated (0.0081s) ==============================

USHQMC5705:war hirenm$ RAILS_ENV=production java -server -jar jrbin.war -S puma -t 5:5 -p 3000 -c config/puma.rb
ERROR: org.jruby.exceptions.RuntimeError: (AmbiguousOption) ambiguous option: -c
USHQMC5705:war hirenm$ RAILS_ENV=production java -jar jrbin.war -S puma -t 5:5 -p 3000 -c config/puma.rb
ERROR: org.jruby.exceptions.RuntimeError: (AmbiguousOption) ambiguous option: -c

# run war file without puma config file
USHQMC5705:war hirenm$ RAILS_ENV=production java -jar jrbin.war -S puma -t 5:5 -p 3000
Puma starting in single mode...
* Version 4.3.7 (jruby 9.2.13.0 - ruby 2.5.7), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
ERROR: No application configured, nothing to run
ERROR: org.jruby.exceptions.SystemExit: (SystemExit) exit

# run war file without puma config file and add server option
USHQMC5705:war hirenm$ RAILS_ENV=production java -server -jar jrbin.war -S puma -t 5:5 -p 3000
Puma starting in single mode...
* Version 4.3.7 (jruby 9.2.13.0 - ruby 2.5.7), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
ERROR: No application configured, nothing to run
ERROR: org.jruby.exceptions.SystemExit: (SystemExit) exit

# create executable war file -> fails
USHQMC5705:jrbin hirenm$ bundle exec warble executable war
java -classpath "/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/jruby-jars-9.2.13.0/lib/jruby-core-9.2.13.0-complete.jar":"/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/jruby-jars-9.2.13.0/lib/jruby-stdlib-9.2.13.0.jar":"/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/jruby-rack-1.1.21/lib/jruby-rack-1.1.21.jar"  org.jruby.Main -S jrubyc  "app/controllers/application_controller.rb" "app/controllers/cars_controller.rb" "app/helpers/application_helper.rb" "app/helpers/cars_helper.rb" "app/jobs/application_job.rb" "app/mailers/application_mailer.rb" "app/models/application_record.rb" "app/models/car.rb" "db/migrate/20201202235834_create_cars.rb" "db/schema.rb" "db/seeds.rb" "config/application.rb" "config/boot.rb" "config/environment.rb" "config/environments/development.rb" "config/environments/production.rb" "config/environments/test.rb" "config/initializers/application_controller_renderer.rb" "config/initializers/assets.rb" "config/initializers/backtrace_silencers.rb" "config/initializers/content_security_policy.rb" "config/initializers/cookies_serializer.rb" "config/initializers/filter_parameter_logging.rb" "config/initializers/inflections.rb" "config/initializers/mime_types.rb" "config/initializers/wrap_parameters.rb" "config/puma.rb" "config/routes.rb" "config/warble.rb"
Downloading jetty-runner-9.2.9.v20150224.jar
warble aborted!
SocketError: Failed to open TCP connection to repo2.maven.org:80 (initialize: name or service not known) - http://repo2.maven.org/maven2/org/eclipse/jetty/jetty-runner/9.2.9.v20150224/jetty-runner-9.2.9.v20150224.jar
org/jruby/ext/timeout/Timeout.java:114:in `timeout'
org/jruby/ext/timeout/Timeout.java:90:in `timeout'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/web_server.rb:23:in `local_path'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/web_server.rb:81:in `add'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/web_server.rb:97:in `add'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/traits/war.rb:116:in `add_executables'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/traits/war.rb:81:in `update_archive'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/traits.rb:41:in `block in update_archive'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/traits.rb:41:in `update_archive'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/jar.rb:181:in `apply_traits'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/jar.rb:159:in `apply'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/task.rb:118:in `block in define_files_task'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/task.rb:94:in `block in define_main_task'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/task.rb:93:in `block in define_main_task'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/application.rb:79:in `run'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/application.rb:74:in `run'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/bin/warble:11:in `<main>'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/bin/warble:23:in `<main>'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/bin/jruby_executable_hooks:24:in `<main>'

Caused by:
SocketError: initialize: name or service not known
org/jruby/ext/socket/RubyTCPSocket.java:151:in `initialize'
org/jruby/ext/timeout/Timeout.java:114:in `timeout'
org/jruby/ext/timeout/Timeout.java:90:in `timeout'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/web_server.rb:23:in `local_path'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/web_server.rb:81:in `add'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/web_server.rb:97:in `add'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/traits/war.rb:116:in `add_executables'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/traits/war.rb:81:in `update_archive'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/traits.rb:41:in `block in update_archive'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/traits.rb:41:in `update_archive'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/jar.rb:181:in `apply_traits'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/jar.rb:159:in `apply'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/task.rb:118:in `block in define_files_task'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/task.rb:94:in `block in define_main_task'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/task.rb:93:in `block in define_main_task'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/application.rb:79:in `run'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/lib/warbler/application.rb:74:in `run'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/gems/warbler-2.0.5/bin/warble:11:in `<main>'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/bin/warble:23:in `<main>'
/Users/hirenm/.rvm/gems/jruby-9.2.13.0/bin/jruby_executable_hooks:24:in `<main>'
Tasks: TOP => war:files
(See full trace by running task with --trace)

Let me know if there's anything else you require. The rails app is a simple test app with the default scaffold cars model, controller, view.

@daemonzone
Copy link

Same issue here, here's how I solved:

.rbenv/versions/jruby-9.3.2.0/lib/ruby/gems/shared/gems/warbler-2.0.5/lib/warbler/web_server.rb

Changed line 91 from this
@artifact = Artifact.new(ENV["MAVEN_REPO"] || "http://repo2.maven.org/maven2",
to this
@artifact = Artifact.new(ENV["MAVEN_REPO"] || "https://repo.maven.apache.org/maven2",

@podsi
Copy link

podsi commented Sep 23, 2022

Thank you @daemonzone, this worked for me as well. Would be nice if you would open a pull request for that. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants