Disabling echo from webrick
Following the link to the source and suggestion provied by Yet Another Geek, I was able to figure out a way. Set the AccessLog
parameter to [nil, nil]
[]
(Changed following suggestion by Robert Watkins).
s = WEBrick::HTTPServer.new(
Port: 3000,
BindAddress: "localhost",
Logger: WEBrick::Log.new("/dev/null"),
AccessLog: [],
)
Somehow WEBrick is taking over my Sinatra app launch, how to turn it off?
The line ruby basics.rb
means that you are running Sinatra with Ruby, not Node.js.
If you want your Sinatra application launch a simple CGI daemon, not a complete HTTP server, you should use Sinatra::Base
, not the normal Sinatra
infrastructure. Applications based on Sinatra::Base
do not launch WEBRick or any other server at startup and rely on an external HTTP server.
Have a look at the introduction to Sinatra::Base
.
Disable Rack::CommonLogger without monkey patching
Puma adds logging middleware to your app if you are in development mode and haven’t set the --quiet
option.
To stop Puma logging in development, pass the -q
or --quiet
option on the command line:
puma -p 3001 -q
or if you are using a Puma config file, add quiet
to it.
gem executable that starts sinatra server not working
You need to add
enable :run
to your application file, so that the built in web server will start.
From the Sinatra configuration settings:
By default, this setting is enabled only when the :app_file matches $0. i.e., when running a Sinatra app file directly with ruby myapp.rb.
When running the file directly this condition is true so the web server starts. When packaged as a gem however, the executable file that is actually run is really a wrapper script around your application file created by rubygems, so the condition is false and the web server doesn't start.
Ruby TCPServer always delay on dns reverse lookup? - how to disable?
The problem depends on my client machine where I run on MAC OSX Mav.
The used telnet client tries to open IPv6 connection and afterwards IPv4.
To solve the delay, just open connection with
telnet -4 my-server 3333
I have build a small connect echo servive where you can check resolves and timings.
If you change NO_REVERSE_LOOKUP you will get IPs or ADDRESSes and if not resolveable, different response times.
require 'socket'
NO_REVERSE_LOOKUP = true
CONNECT_PORT = 3333
puts "#{Time.now} Starting service on port: #{CONNECT_PORT}"
# the full hell - just to test if anything meets what we want
TCPServer.do_not_reverse_lookup = NO_REVERSE_LOOKUP
BasicSocket.do_not_reverse_lookup = NO_REVERSE_LOOKUP
Socket.do_not_reverse_lookup = NO_REVERSE_LOOKUP
srv = TCPServer.open(CONNECT_PORT)
puts "#{Time.now} Waiting for client"
client = srv.accept
puts "#{Time.now} Client connected"
client.do_not_reverse_lookup = NO_REVERSE_LOOKUP
client.print "Hello connected\n"
# in case that we disabled reverse lookup, we should only receive IP Adresses
puts "#{Time.now} Getting server address infos"
puts "SERVER INFO:"
puts NO_REVERSE_LOOKUP ? client.addr(:numeric) : client.addr(:hostname)
puts ""
puts "#{Time.now} Getting remote client infos"
puts "REMOTE INFO:"
puts NO_REVERSE_LOOKUP ? client.peeraddr(:numeric) : client.peeraddr(:hostname)
###
puts "#{Time.now} Closing connection"
client.close
puts "#{Time.now} End"
Thanks to drbrain from #ruby-lang irc for pointing me to the IPv6 problem.
Exposing/Publishing ports from docker
At the end of the day I never found out what I was doing wrong. I took a different approach to the problem and solved it by using Forman and Thin.
My Dockerfile:
FROM buildpack-deps:jessie
ENV RUBY_MAJOR 2.2
ENV RUBY_VERSION 2.2.3
ENV RUBY_DOWNLOAD_SHA256 df795f2f99860745a416092a4004b016ccf77e8b82dec956b120f18bdc71edce
ENV RUBYGEMS_VERSION 2.4.8
# skip installing gem documentation
RUN echo 'install: --no-document\nupdate: --no-document' >> "$HOME/.gemrc"
# some of ruby's build scripts are written in ruby
# we purge this later to make sure our final image uses what we just built
RUN apt-get update \
&& apt-get install -y bison libgdbm-dev ruby \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /usr/src/ruby \
&& curl -fSL -o ruby.tar.gz "http://cache.ruby-lang.org/pub/ruby/$RUBY_MAJOR/ruby-$RUBY_VERSION.tar.gz" \
&& echo "$RUBY_DOWNLOAD_SHA256 *ruby.tar.gz" | sha256sum -c - \
&& tar -xzf ruby.tar.gz -C /usr/src/ruby --strip-components=1 \
&& rm ruby.tar.gz \
&& cd /usr/src/ruby \
&& autoconf \
&& ./configure --disable-install-doc \
&& make -j"$(nproc)" \
&& make install \
&& apt-get purge -y --auto-remove bison libgdbm-dev ruby \
&& gem update --system $RUBYGEMS_VERSION \
&& rm -r /usr/src/ruby
# install things globally, for great justice
ENV GEM_HOME /usr/local/bundle
ENV PATH $GEM_HOME/bin:$PATH
ENV BUNDLER_VERSION 1.10.6
RUN gem install bundler --version "$BUNDLER_VERSION" \
&& bundle config --global path "$GEM_HOME" \
&& bundle config --global bin "$GEM_HOME/bin"
# don't create ".bundle" in all our apps
ENV BUNDLE_APP_CONFIG $GEM_HOME
COPY app /auth_app
WORKDIR /auth_app
RUN bundle install
CMD ["foreman","start","-d","/auth_app"]
EXPOSE 4567
My Gemfile:
source 'https://rubygems.org'
gem 'sinatra'
gem 'foreman'
gem 'nori'
gem 'thin'
gem 'rack'
gem 'rack-test'
My Procfile:
web: bundle exec rackup --env dev config.ru -p 4567 -s thin -o 0.0.0.0
My docker command running it:
docker run -p 4567:4567 -d auth_app
I didn't change any code within the app, just the docker deployment setup, it worked like a charm then. Thank you for all your answers, they helped me at least to concentrate onto right problems and ask right questions to get this running.
Related Topics
How to Use Activesupport::Configurable with Rails Engine
Exception_Notification for Delayed_Job
Using Activemodel::Serializer in Rails - JSON Data Differs Between JSON and Index Response
Log Doesn't Work in Production with Delayed Job
Rails Routes: Get Without Param :Id
In Ruby, How to Find Out If a String Is Not in an Array
Ruby -V Dyld: Library Not Loaded: /Usr/Local/Lib/Libgmp.10.Dylib
Is It a Good Idea to Purge Old Rails Migration Files
Rails 3.2.8 - How to Get the Week Number from Rails
How to Reference a Method in Another Ruby Code File
Initialize a Ruby Class from an Arbitrary Hash, But Only Keys with Matching Accessors
How to Programmatically Check If a Certificate Has Been Revoked