How to configure webrick port in eclipse? - ruby-on-rails

Using Eclipse/Aptana, how can I change the default port for WEBrick from 3000 to anything else, using a configuration settings in the project? E.g. I want to be able to have multiple servers running for different projects on different ports.
I don't see where (in Eclipse or my project settings) I can set the port? I run the server by right-clicking the project and choosing "Run Server".
Using: Eclipse Kepler; Aptana Studio 3 (3.4.2)

In Aptana Studio Go to Window > Show View > Servers.
There you can select to delete and update servers related to your apps.

You can set the port for WEBrick with the -p parameter. You should be able to append the param to your run configuration.
# ruby script/server -p 8080
There's also some other params which you might find useful:
# ruby script/server --help
=> Booting WEBrick...
Usage: ruby server [options]
-p, --port=port Runs Rails on the specified port.
Default: 3000
-b, --binding=ip Binds Rails to the specified ip.
Default: 0.0.0.0
-e, --environment=name Specifies the environment to run this server under (test/development/production).
Default: development
-m, --mime-types=filename Specifies an Apache style mime.types configuration file to be used for mime types
Default: none
-d, --daemon Make Rails run as a Daemon (only works if fork is available -- meaning on *nix).
-c, --charset=charset Set default charset for output.
Default: UTF-8
-h, --help Show this help message.

Related

How to change WEBrick :AccessLog option when running RedMine?

I'm running RedMine via WEBrick using the following command line (simplified):
bundle exec rails server webrick -e production -p 3012 -P '/var/lib/redmine/redmine.pid'
I don't like how WEBrick outputs the peer address at the beginning of its access log lines (because I'm running it behind nginx and the peer address is always 127.0.0.1), so I want to change the access log format.
I know that I need to tune the :AccessLog config option for WEBrick, but I don't know how to get my hands on it. WEBrick is run by the rails server command, via the rack abstraction, and I don't see an obvious way to pass the necessary configuration to WEBrick.
So, is there any way to do it? Some command line switch? -c is the only switch that accepts some kind of configuration file, but it references "rackup", and I have no idea how to work with it.
Maybe it can be done by changing configuration files? I tried to modify additional_environment.rb by adding config[:AccessLog] = [ [ $stderr, WEBrick::AccessLog::COMMON_LOG_FORMAT ] ], but it had no effect (although the file was executed), so I assume this file's config is not what is passed to WEBrick.
I'm pretty sure there is some way to configure this option without creating a new Rails application and invoking WEBrick manually, and hopefully even without changing RedMine files.

Rubymine: debugging using installed Puma-dev?

Is it possbile to have Rubymine connect to (and restart) an installed/running instance of Puma-dev for the debugging session?
I use Puma-dev to test my Rails app on "Appname".test, yet if I need to debug something in the app and want to use Rubymine's built-in debugger, I can only let it start an additional instance of Puma on Port 3000 (or whatever Port I choose) but not the already running Puma-dev on port 80/443.
Is it at all possible?
This is possible with remote debugging. To configure, you have to make some changes to your app:
Add export RUBY_DEBUG_PORT=1234 to .env or .powenv or any file puma-dev will load an environment variable from. Feel free to use whatever port you'd like, although RubyMine uses 1234 by default.
Add the ruby-debug-ide and debase gems to your project's Gemfile.
Add an initializer to your project to initialize remote debugging, like so:
if Rails.env.development? && ENV['RUBY_DEBUG_PORT']
Debugger.start_server nil, ENV['RUBY_DEBUG_PORT'].to_i
end
Restart puma-dev.
Go to Edit Configurations in RubyMine and add a "Ruby remote debug" config. Name it whatever you'd like. Change the port to the port you set via RUBY_DEBUG_PORT. Set your local and remote root folders to your project root.
Select your newly created configuration and click the Debug button. It should connect to the debugger running in your puma-dev process.

Remote SDK starting rails server exits while ssh cli session starts

I'm working on a headless VM and configured my hosts Rubymine to use the remote SDK through the NAT interface of VirtualBox.
After configuring the remote SDK, my Run/Debug configuration looks fine. When I start the server, it returns the following output
/usr/bin/ruby -e '$stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)' /home/user/project/bin/rails server -b 0.0.0.0 -p 3000 -e development
git://github.com/rails/sprockets-rails.git (at master#06852de) is not yet checked out. Run `bundle install` first.
Process finished with exit code 11
When I fire up the same command, ssh'ed into the VM the server starts fine
The SDK seems to work; it invokes /usr/bin/ruby which is the proper path (no rvm)
The installed gem lib should be alright since everything works in ssh command line
The relevant lines in the Gemfile are
gem 'sprockets-rails', github: 'rails/sprockets-rails'
ruby '2.3.1'
gem 'rails', '~> 4.2'
The gems are installed in ~/.gem/ruby/2.3.0/bin/
The advice of the output to run bundle install is useless, since I did and works anyway in cli. It seems like Rubymine needs adjustments. Has anyone an idea what I could do about?
Found the answer!
Reason is the non-interactive shell session which sources less of your dotfiles (See man bash and search for non-interactive)
I knew it has nothing to do with Rubymine when I tried on my host system:
ssh user#127.0.0.1 "/usr/bin/ruby /home/user/project/bin/rails server -b 0.0.0.0 -p 3000 -e development"
which provides the same output as Rubymine did
also check ssh user#127.0.0.1 "env" to see variables of your shell environment.
man sshd 8 says how to set the environment, using the ~/.ssh/environment (file on the server, since man page is sshd) to store key/value pairs like KEY=value
This file is read into the environment at login (if it exists). It can
only contain empty lines, comment lines (that start with ‘#’), and
assignment lines of the form name=value. The file should be writable
only by the user; it need not be readable by anyone else. Environment
processing is disabled by default and is controlled via the
PermitUserEnvironment option.
Note the PermitUserEnvironment option, goes into your sshd.conf on the server

how rails server understand which project to run

I am new to rails . I have multiple projects in my workspace. When i hit http://localhost:3000/ , I want to know how to distinguish between different projects. Say there are three projects A,B,C in my workspace and I want to run A in my browser. How to do so ?
I hope you are familiar with rvm, and must be using that.
If you want to run a particular project. Go to your project's directory and hit rails s.
if you want to run servers of more than one projects at one time, then give the port also to run the server. e.g:
rails s -p 3001
rails s -p 3002
In your terminal locate in the folder of your project
$ cd projects_folder
$ cd project_A
$ rails s
You will see this message
=> Booting Thin
=> Rails 4.2.5 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Thin web server (v1.6.4 codename Gob Bluth)
Maximum connections set to 1024
Listening on localhost:3000, CTRL+C to stop
Minimize your terminal and open http://localhost:3000 in your favorite browser.
When you want to change of project maximize your terminal and
press ctrl+c to stop the process
Locate in other folder
$ cd ..
$ cd project_B
$ rails s
I recommend you read this to learn how to navigate in terminal

Rails - switch environment to production automatically

I am doing a project in rails, and i just run this project in console by following command:
$ rails server
But it runs in development mode. I want when i run "rails server", it runs in production mode, what script must i edit to set the environment ?
Easy:
rails server RAILS_ENV=production
Or:
rails s -e production
Or you meant without this extra thing? If that so, it depends on which server you use. You can install Puma for example, and add config file, in which you can specify the default environment.
This question could help in case of set rails env for ngnx or passenger.
All the possible operations on the rails server
-p port: Specify the port to run on
-b ip: Bind to a specific IP address
-e name: Use a specific Rails environment (like production)
-d: Run in daemon mode
-h: Display a help message with all command-line options

Resources