Hi Unicorn friends, I wanted to try out Unicorn as my development server and I see that I need to perform some configuration to make this work nicely with rails.>From what I can tell the only real things I need to do to make unicornsimilar to the default rails server is to supply a config file with: listen 3000 logger Logger.new(STDOUT) ... After creating this file, I was kind of confused as to how to proceed.. Should I made a bash alias like alias unicorn="unicorn_rails -c /path/to/unicorn_config.rb" and lastly, is there a convention where a configuration file like this should go on a unix/OS X system? Thank you kindly. Patrick J. Collins http://collinatorstudios.com
"Patrick J. Collins" <patrick at collinatorstudios.com> wrote:> Hi Unicorn friends, > > I wanted to try out Unicorn as my development server and I see that I > need to perform some configuration to make this work nicely with rails. > >From what I can tell the only real things I need to do to make unicorn > similar to the default rails server is to supply a config file with: > > listen 3000 > logger Logger.new(STDOUT)Hi Patrick, You shouldn''t even need the logger directive, it goes to stderr by default so your console will still show it.> After creating this file, I was kind of confused as to how to proceed.. > Should I made a bash alias like > > alias unicorn="unicorn_rails -c /path/to/unicorn_config.rb"I generally avoid shell aliases for per-app/project things since I split my work across different apps + terminals + machines. If I''m (rarely) developing an app that _requires_ a persistently running web server, I''d just run in the foreground and Ctrl-C/<uparrow+enter> to use my shell history. Normally I just write integration tests (sometimes starting unicorn (or zbatery) + hitting it with curl, but often just mocking a Rack env). Unlike most folks that develop apps that run over HTTP, I have a strong aversion to web browsers. I''d rather pipe curl output to "vim -" if I have to look at any text output from the application. You''ll probably get different answers from other folks here :)> and lastly, is there a convention where a configuration file like this > should go on a unix/OS X system?Nothing that I know of. It''s quite common for Rails apps to have a config/ directory, so maybe the unicorn config file is suitable there...
> You shouldn''t even need the logger directive, it goes to stderr by > default so your console will still show it.Hmm that''s odd because I noticed as soon as I began using unicorn that I got very little output. For example, running my app and browsing to various pages, this is all I see: I, [2012-02-22T19:38:30.511485 #8933] INFO -- : listening on addr=0.0.0.0:3000 fd=3 I, [2012-02-22T19:38:30.511938 #8933] INFO -- : worker=0 spawning... I, [2012-02-22T19:38:30.514042 #8933] INFO -- : master process ready I, [2012-02-22T19:38:30.515943 #8934] INFO -- : worker=0 spawned pid=8934 I, [2012-02-22T19:38:30.516671 #8934] INFO -- : Refreshing Gem list DEPRECATION WARNING: Calling set_table_name is deprecated. Please use `self.table_name = ''the_name''` instead. (called from require at /Users/patrick/.rvm/gems/ruby-1.9.2-p290 at global/gems/bundler-1.1.rc.7/lib/bundler/runtime.rb:68) I, [2012-02-22T19:38:56.879509 #8934] INFO -- : worker=0 ready I, [2012-02-22T19:49:22.737427 #8933] INFO -- : SIGWINCH ignored because we''re not daemonized I, [2012-02-22T19:49:35.800600 #8933] INFO -- : SIGWINCH ignored because we''re not daemonized I, [2012-02-22T20:02:05.792427 #8933] INFO -- : SIGWINCH ignored because we''re not daemonized I, [2012-02-22T20:03:07.315092 #8933] INFO -- : SIGWINCH ignored because we''re not daemonized I, [2012-02-22T20:03:36.330349 #8933] INFO -- : SIGWINCH ignored because we''re not daemonized I, [2012-02-22T20:04:33.278243 #8933] INFO -- : SIGWINCH ignored because we''re not daemonized I, [2012-02-22T20:05:33.188828 #8933] INFO -- : SIGWINCH ignored because we''re not daemonized ... None of the development.log output is getting piped into this, so that''s why I thought doing the Logger.new(STDOUT) would get that behavior to happen just as it does with the default rails server. Patrick J. Collins http://collinatorstudios.com
"Patrick J. Collins" <patrick at collinatorstudios.com> wrote:> > You shouldn''t even need the logger directive, it goes to stderr by > > default so your console will still show it. > > Hmm that''s odd because I noticed as soon as I began using unicorn that I got > very little output. For example, running my app and browsing to various pages, this is all I see:<snip>> None of the development.log output is getting piped into this, so that''s why I > thought doing the Logger.new(STDOUT) would get that behavior to happen just as > it does with the default rails server.Odd, not sure what Rails is doing (I don''t normally use Rails). It must be something weird with the way Rails modifies all existing logger objects (I know it clobbers the default logger formatter somehow as mentioned in the FAQ). Oh well, I suppose your workaround is as good as any.
> "Patrick J. Collins" <patrick at collinatorstudios.com (mailto:patrick at collinatorstudios.com)> wrote: > > Hmm that''s odd because I noticed as soon as I began using unicorn that I got > > very little output. For example, running my app and browsing to various pages, this is all I see: >Rails logs to a file by default, so you probably need to set the Rails logger somewhere in your config: Rails.logger = ::Logger.new($stdout) -- Alex Sharp Zaarly, Inc | @ajsharp | github.com/ajsharp | alexjsharp.com
> Normally I just write integration tests (sometimes starting unicorn (or > zbatery) + hitting it with curl, but often just mocking a Rack env). > Unlike most folks that develop apps that run over HTTP, I have a strong > aversion to web browsers. I''d rather pipe curl output to "vim -" if I > have to look at any text output from the application.This is slightly off topic, so I will make this concise, or this can be taken offline. What you are talking about, Eric, is exactly the workflow I am working toward. I am almost there, but still too dependent on the browser. So 2 questions: 1) Would you share what you use for integrations tests for rails and rack apps in general? (rack test, minitest, capybara, etc.) 2) Are there any resources you would point to going into further detail? Feel free to respond here or directly, as this is a tangent. Thanks, Matt
Hi, No one else really replied on this--- But I am wondering if anyone can tell me how I can get my rails development log to stream (as in tail -f) into the unicorn server output... I thought I needed to do logger Logger.new(STDOUT) in my config file, but that doesn''t seem to do it. Any ideas? Patrick J. Collins http://collinatorstudios.com On Wed, 22 Feb 2012, Patrick J. Collins wrote:> Hi Unicorn friends, > > I wanted to try out Unicorn as my development server and I see that I > need to perform some configuration to make this work nicely with rails. > From what I can tell the only real things I need to do to make unicorn > similar to the default rails server is to supply a config file with: > > listen 3000 > logger Logger.new(STDOUT) > > ... > > After creating this file, I was kind of confused as to how to proceed.. > Should I made a bash alias like > > alias unicorn="unicorn_rails -c /path/to/unicorn_config.rb" > > and lastly, is there a convention where a configuration file like this > should go on a unix/OS X system? > > Thank you kindly. > > Patrick J. Collins > http://collinatorstudios.com > >
Hey Patrick, Sorry, I replied a few days ago but looks like I missed your email on the CC. This should solve it:> "Patrick J. Collins" <patrick at collinatorstudios.com (mailto:patrick at collinatorstudios.com)> wrote: > > Hmm that''s odd because I noticed as soon as I began using unicorn that I got > > very little output. For example, running my app and browsing to various pages, this is all I see: >Rails logs to a file by default, so you probably need to set the Rails logger somewhere in your config: Rails.logger = ::Logger.new($stdout) -- Alex Sharp Zaarly, Inc | @ajsharp | github.com/ajsharp (http://github.com/ajsharp) | alexjsharp.com (http://alexjsharp.com)
Matt Smith <matt at nearapogee.com> wrote:> Eric Wong wrote: > > Normally I just write integration tests (sometimes starting unicorn (or > > zbatery) + hitting it with curl, but often just mocking a Rack env). > > Unlike most folks that develop apps that run over HTTP, I have a strong > > aversion to web browsers. I''d rather pipe curl output to "vim -" if I > > have to look at any text output from the application. > > This is slightly off topic, so I will make this concise, or this can > be taken offline. > > What you are talking about, Eric, is exactly the workflow I am working > toward. I am almost there, but still too dependent on the browser. So > 2 questions: > 1) Would you share what you use for integrations tests for rails and > rack apps in general? (rack test, minitest, capybara, etc.)For Rack apps, I normally use test/unit (minitest in 1.9) + Rack::Mock*. test/test_watcher.rb in raindrops[1] is a public example of that. I don''t develop a lot of Rack apps, though. I haven''t touched Rails in ages, but last time I used test/unit and some builtin Rails test extensions. If I''m testing within Ruby, I stay with test/unit because it''s bundled/maintained with the latest version(s) of Ruby. Back in the day, I know some projects had trouble migrating to Ruby 1.9.1 because rspec wasn''t 1.9-compatible at the time (it is now). Back to Unicorn (and Rainbows!) ------------------------------- For testing HTTP servers (or anything that interacts with non-Ruby-components), I''ll use scripts in other languages (shell/Perl/awk) and external tools (e.g. curl) to shake out potential bugs. I worry about "self-cancelling" bugs which can be hidden from tests because I didn''t understand something (often Ruby itself) well enough. Ruby 1.9 encodings is/was especially confusing to me, so I reached outside of Ruby in many cases. [1] - git clone git://bogomips.org/raindrops [2] - For the few Rack apps I write, almost all of them are APIs or targeted at lynx or curl users. I hate pretty things :)