Re: run my Camping app as a Rack app

2011-10-12 Thread Magnus Holm
On Tue, Oct 11, 2011 at 18:21, Nokan Emiro  wrote:
> Thanks for the explanation.
>
> I have had the create method in my application, it calls
> Models::create_scheme, because I have migrations too.
> (Everything encapsulated, that's what I like about Camping.)
>
> Actually the problem with X.create was that my
> fastcgi-camping-server did not initialize any ActiveRecord
> connections, while the standard camping server did.  After I
> placed this
>
> ActiveRecord::Base.establish_connection(
>     :adapter  => "mysql",
>     :host => "localhost",
>     :user => "*",
>     :password => "**",
>     :database => "databasename"
> )
>
> before the X.create line, it worked fine.  Anyway that generated
> a question.  As you can see I replaced sqlite to mysql,
> and now I can see in the mysql database, that table names
> are in form of databasename_tablename, and I have an extra
> databasename_schema_infos table too.  How can I turn this
> behavior off?  It's not critical, but a bit ugly.
>
> uzlee

This should remove the prefix:

  def ActiveRecord::Base.table_name_prefix; '' end

You probably don't want to get rid of schema_infos though, since
that's kinda essential for migrations.
___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Re: run my Camping app as a Rack app

2011-10-11 Thread Nokan Emiro
Thanks for the explanation.

I have had the create method in my application, it calls
Models::create_scheme, because I have migrations too.
(Everything encapsulated, that's what I like about Camping.)

Actually the problem with X.create was that my
fastcgi-camping-server did not initialize any ActiveRecord
connections, while the standard camping server did.  After I
placed this

ActiveRecord::Base.establish_connection(
:adapter  => "mysql",
:host => "localhost",
:user => "*",
:password => "**",
:database => "databasename"
)

before the X.create line, it worked fine.  Anyway that generated
a question.  As you can see I replaced sqlite to mysql,
and now I can see in the mysql database, that table names
are in form of databasename_tablename, and I have an extra
databasename_schema_infos table too.  How can I turn this
behavior off?  It's not critical, but a bit ugly.

uzlee



On Tue, Oct 11, 2011 at 9:50 AM, Magnus Holm  wrote:

> Now that you have solved your real problem, let me explain this one too:
>
> X.create is purely a convention so you can write code that will run on
> startup inside your application. So you can write this in your
> application:
>
>  def X.create
># run migrations etc.
>  end
>
> Then a "proper" Camping server (like your FastCGI-wrapper) will make
> sure to invoke X.create. Of course, a proper Camping server must also
> take care to handle applications that *don't* define X.create, so that
> line should actually look like this:
>
>  # inside the server:
>  X.create if X.respond_to? :create
>
>
___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Re: run my Camping app as a Rack app

2011-10-11 Thread Magnus Holm
On Sun, Oct 9, 2011 at 15:43, Nokan Emiro  wrote:
> Hi,
>
> Could you please show me the preferred/nicest way
> to run my Camping application as a Rack all?  I like
> doing my work in Rack because it's easy to run my app
> in a standalone webserver, or "mount" it to a path in
> my production environment as a FastCGI app.
>
> require 'rubygems'
> require 'rack'
> app = ...
> Rack::Handler::FastCGI.run app, :Port => 
>
> I use Camping as a proof-of-concept framework, but it's
> time to turn some of my apps into production, and I'm looking
> for the right way to do this, and I think this is to make it run
> as a Rack app.  I've found code snippets on the net but
> none of them worked.  This one is the less wrong one:
>
> require 'rubygems'
> require 'rack'
> require 'camping'
>
> Camping.goes :X
> module X
>     # my Camping app here #
> end
>
> X.create
>
> Rack::Handler::FastCGI.run X, :Port => 8899
>
> I know it's not good.  Basicly my question is:  how to repair this? :)
>
> I have two problems:
>
> 1) X.create makes ugly error messages

Now that you have solved your real problem, let me explain this one too:

X.create is purely a convention so you can write code that will run on
startup inside your application. So you can write this in your
application:

  def X.create
# run migrations etc.
  end

Then a "proper" Camping server (like your FastCGI-wrapper) will make
sure to invoke X.create. Of course, a proper Camping server must also
take care to handle applications that *don't* define X.create, so that
line should actually look like this:

  # inside the server:
  X.create if X.respond_to? :create
___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Re: run my Camping app as a Rack app

2011-10-10 Thread Anthony Durity
Hi all,

What I do is check the ENV variable ... and I use Passenger Phusion to run
my Rack apps

So ... like this ... install Apache and Passenger Phusion and point
passenger at a rack_apps dir (under the web server root)

Now I have

/var/www/localhost/htdocs <- web server doc root

/var/www/localhost/htdocs/rack_apps/* <- rack_apps

  cd /var/www/localhost/htdocs
and
  camping rack_apps/*/config.ru
runs all my Camping apps in dev mode

or ... to run as a rack app (using passenger) at the end of your
config.ruput this addendum

Camping.goes :MyApp

module MyApp
# blah blah blah
end

case ENV['RACK_ENV']
  when 'development'
# set a mode var?
debug "i'm in rack dev mode"
ENV['MODE'] = 'development'
  when 'production'
# set a mode var?
debug "i'm in rack live mode"
ENV['MODE'] ||= 'production'

run MyApp # !! this is the important bit !

  else
ENV['MODE'] = nil
end

if __FILE__ == $0
  # this library may be run as a standalone script
  # as in -> ruby rack_apps/___/config.ru
  # dunno why you'd want to do that but anyway

  # set a mode var?
  debug "i'm in standalone mode"
  ENV['MODE']='standalone'
end

I don't know, maybe this is all obvious but it took me a little while to
figure it out cuz I'm a bit slow about these things.

Regards,
Anthony

On Sun, Oct 9, 2011 at 4:43 PM, Nokan Emiro  wrote:

> Hi,
>
> Could you please show me the preferred/nicest way
> to run my Camping application as a Rack all?  I like
> doing my work in Rack because it's easy to run my app
> in a standalone webserver, or "mount" it to a path in
> my production environment as a FastCGI app.
>
> require 'rubygems'
> require 'rack'
> app = ...
> Rack::Handler::FastCGI.run app, :Port => 
>
> I use Camping as a proof-of-concept framework, but it's
> time to turn some of my apps into production, and I'm looking
> for the right way to do this, and I think this is to make it run
> as a Rack app.  I've found code snippets on the net but
> none of them worked.  This one is the less wrong one:
>
> require 'rubygems'
> require 'rack'
> require 'camping'
>
> Camping.goes :X
> module X
> # my Camping app here #
> end
>
> X.create
>
> Rack::Handler::FastCGI.run X, :Port => 8899
>
> I know it's not good.  Basicly my question is:  how to repair this? :)
>
> I have two problems:
>
> 1) X.create makes ugly error messages
> 2) if I comment out the X.create line, it seems to work, but does
> not really do.  It listens for connections on 8899, but it halt on
> the first fcgi connection from the webserver.
>
> thx,
> uzlee
>
> ___
> Camping-list mailing list
> Camping-list@rubyforge.org
> http://rubyforge.org/mailman/listinfo/camping-list
>
___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Re: run my Camping app as a Rack app

2011-10-09 Thread Nokan Emiro
> require 'rack'
> require 'pp'
>
> App = lambda do |env|
> body = ''
> PP.pp env, body
> [200, {'Content-Type' => 'text/plain'}, body]
> end
>
> Rack::Handler::FastCGI.run App, :Port => 9000
>


{"HTTP_ACCEPT"=>
  "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
 "HTTP_HOST"=>"www.mytestsite.com",
 "SERVER_NAME"=>"mytestsite.com",
 "REQUEST_PATH"=>"/",
 "rack.url_scheme"=>"http",
 "HTTP_KEEP_ALIVE"=>"115",
 "HTTP_USER_AGENT"=>
  "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.23) Gecko/20110921
Ubuntu/10.04 (lucid) Firefox/3.6.23",
 "DOCUMENT_URI"=>"/",
 "rack.errors"=>#,
 "HTTP_ACCEPT_LANGUAGE"=>"hu,en-us;q=0.7,en;q=0.3",
 "SERVER_PROTOCOL"=>"HTTP/1.1",
 "FCGI_ROLE"=>"RESPONDER",
 "rack.version"=>[1, 1],
 "rack.run_once"=>false,
 "REMOTE_ADDR"=>"**.***.**.**",
 "SERVER_SOFTWARE"=>"nginx/1.0.5",
 "SERVER_ADDR"=>"192.168.100.200",
 "SCRIPT_NAME"=>"",
 "HTTP_VERSION"=>"HTTP/1.1",
 "rack.multithread"=>false,
 "rack.multiprocess"=>true,
 "REMOTE_PORT"=>"35088",
 "REQUEST_URI"=>"/",
 "HTTP_ACCEPT_CHARSET"=>"ISO-8859-1,utf-8;q=0.7,*;q=0.7",
 "SERVER_PORT"=>"443",
 "DOCUMENT_ROOT"=>"/var/www/mytestsite.com",
 "REQUEST_METHOD"=>"GET",
 "SCRIPT_FILENAME"=>"/var/www/mytestsite.com/",
 "rack.input"=>
  #,
   @rewindable_io=nil,
   @unlinked=false>,
 "HTTP_CONNECTION"=>"keep-alive",
 "HTTP_ACCEPT_ENCODING"=>"gzip,deflate",
 "REDIRECT_STATUS"=>"200",
 "GATEWAY_INTERFACE"=>"CGI/1.1",
 "QUERY_STRING"=>""}


You are right, there is no PATH_INFO.  This line in the webserver
config file helped the fastcgi problem:

fastcgi_param PATH_INFO $fastcgi_path_info;


Thanks a lot!
uzlee
___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Re: run my Camping app as a Rack app

2011-10-09 Thread Jenna Fox
It looks as if your application is getting a FastCGI request without the 
'PATH_INFO' environment variable. I'm not too sure what to make of that. Can 
you try a rackup which runs this app?

require 'rack'
require 'pp'

App = lambda do |env|
body = ''
PP.pp env, body
[200, 'Content-Type' => 'text/plain', body]
end

Rack::Handler::FastCGI.run App, :Port => 9000

and let us know what it prints out as being in the environment. Maybe your 
webserver doesn't provide PATH_INFO over FastCGI. If that's the case, we'll 
need to consider how we can be compatible with that.

—
Jenna

On 10/10/2011, at 6:24 AM, Nokan Emiro wrote:

> The app itself implements Rack protocol. 
> 
> 
> Yes, that's what I've already tried.  It is the case when my
> app stops whenever the first fastcgi request arrives:
> 
> /usr/lib/ruby/1.8/rack/utils.rb:23:in `unescape': undefined method `tr' for 
> nil:NilClass (NoMethodError)
> from (eval):33:in `call'
> from /usr/lib/ruby/1.8/rack/session/cookie.rb:37:in `call'
> from (eval):38:in `call'
> from /usr/lib/ruby/1.8/rack/content_length.rb:13:in `call'
> from /usr/lib/ruby/1.8/rack/handler/fastcgi.rb:57:in `serve'
> from /usr/lib/ruby/1.8/rack/handler/fastcgi.rb:25:in `run'
> from /usr/lib/ruby/1.8/rack/handler/fastcgi.rb:24:in `each'
> from /usr/lib/ruby/1.8/rack/handler/fastcgi.rb:24:in `run'
> ...
> 
> What I do here is:
> 
> require 'camping'
> require 'camping/session'
> Camping.goes :App
> module App
>  #   .  here is my Camping App
> end
> Rack::Handler::FastCGI.run App, :Port => 9000
> 
> ...and configure webserver to send fcgi queries to 9000.
> 
> Is this a Rack problem?  (In this case I'm sorry bothering you!)
> 
> uzlee
> 
> ___
> Camping-list mailing list
> Camping-list@rubyforge.org
> http://rubyforge.org/mailman/listinfo/camping-list

___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Re: run my Camping app as a Rack app

2011-10-09 Thread Nokan Emiro
> Does it work the "regular" way? (via rackup)
>

Yes, rackup makes my app run.  In this case an other
probleme occures, that is more Camping specific.
The ActiveRecord cannot connect to any database.
I think Camping makes some initialization before
starting up my app, that is missing in this case.
(I've tried to call App.create before the Rack handler,
but it's not the right way.)


> Does it work "your" way, but with a different handler?
>

Yes, with (for example) Rack::Handler::WEBrick works the
same way as with rackup.  I can connect to the app with my
browser, but ActiveRecord fails to work.

But I use Rack::Handler::FastCGI with other Rack apps,
and it works.


> Which version of rack you're using?


I tried it with ruby1.9.2 with the latest rack gem a few
days ago, that was 1.3.4.  It did not work, so I downgraded.
Now I'm using ruby 1.8 and the standard librack-ruby1.8
package in Ubuntu.  It's version is 1.1.0-4ubuntu1.

-- 
uzlee
___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Re: run my Camping app as a Rack app

2011-10-09 Thread Nokan Emiro
> Are you running Apache?


No, the webserver is nginx, and I use fastcgi to attach my apps into it.
___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Re: run my Camping app as a Rack app

2011-10-09 Thread David Susco
Are you running Apache? Is so, try installing passenger. I've got half
a dozen apps running via this, it makes things pretty easy.

http://www.modrails.com/

Dave

2011/10/9 Bartosz Dziewoński :
> Does it work the "regular" way? (via rackup)
>
> Does it work "your" way, but with a different handler?
>
> Which version of rack you're using? I can't find any usage of tr
> method in 1.3.4's rack/utils.rb, and line 37 of rack/session/cookie.rb
> is a comment.
>
> -- Matma Rex
> ___
> Camping-list mailing list
> Camping-list@rubyforge.org
> http://rubyforge.org/mailman/listinfo/camping-list
>



-- 
Dave
___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Re: run my Camping app as a Rack app

2011-10-09 Thread Bartosz Dziewoński
Does it work the "regular" way? (via rackup)

Does it work "your" way, but with a different handler?

Which version of rack you're using? I can't find any usage of tr
method in 1.3.4's rack/utils.rb, and line 37 of rack/session/cookie.rb
is a comment.

-- Matma Rex
___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list


Re: run my Camping app as a Rack app

2011-10-09 Thread Nokan Emiro
>
> The app itself implements Rack protocol.
>


Yes, that's what I've already tried.  It is the case when my
app stops whenever the first fastcgi request arrives:

/usr/lib/ruby/1.8/rack/utils.rb:23:in `unescape': undefined method `tr' for
nil:NilClass (NoMethodError)
from (eval):33:in `call'
from /usr/lib/ruby/1.8/rack/session/cookie.rb:37:in `call'
from (eval):38:in `call'
from /usr/lib/ruby/1.8/rack/content_length.rb:13:in `call'
from /usr/lib/ruby/1.8/rack/handler/fastcgi.rb:57:in `serve'
from /usr/lib/ruby/1.8/rack/handler/fastcgi.rb:25:in `run'
from /usr/lib/ruby/1.8/rack/handler/fastcgi.rb:24:in `each'
from /usr/lib/ruby/1.8/rack/handler/fastcgi.rb:24:in `run'
...

What I do here is:

require 'camping'
require 'camping/session'
Camping.goes :App
module App
 #   .  here is my Camping App
end
Rack::Handler::FastCGI.run App, :Port => 9000

...and configure webserver to send fcgi queries to 9000.

Is this a Rack problem?  (In this case I'm sorry bothering you!)

uzlee
___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Re: run my Camping app as a Rack app

2011-10-09 Thread Bartosz Dziewoński
The app itself implements Rack protocol. (That is, if you do
Camping.goes :App, then your "obj" variable would be App - it
implements .call, I think it's all that's needed?)


-- Matma Rex
___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list


Re: run my Camping app as a Rack app

2011-10-09 Thread Nokan Emiro
Yes, You are right, that works in this way.  But this is a
bit different what I want to do.  rackup runs my Rack
application in a webserver (webrick or mongrel), and
I can't use orher handlers than these.  I prefer to use
Rack in a bit lower level.

Suppose that in a standard Ruby script the object `obj`
implements tha Rack interface.  In this case I can simply
run it in this way:

require 'rack'
Rack::Handler::WEBrick.run obj

or

require 'rack'
Rack::Handler::Mongrel.run obj

without all the magic of rackup.  This has the advantage
to use other handlers, not only WEBrick and Mongrel.
I can user Rack::Handler::Thin, ...::CGI, and even
...::FastCGI.

What I really want to do is to run my Camping app using
the Rack::Handler::FastCGI.

I would like to know how can I convert my Camping app into
an object (module, class, lambda or anything else) in Ruby
that implements the Rack interface, and I can push it to
Rack::Handler::FastCGI.run().

If there is any other way to run a Camping app as a fastcgi,
that can be also a good solution.

-- 
uzlee



2011/10/9 Bartosz Dziewoński 

> I'm not sure what are you trying to accomplish.
>
> Can't you just create a config.ru file like this:
>  require './yourapp.rb'
>  run YourApp
>
> And then use `rackup` to start the app?
>
> config.ru files are widely understood, the same thing works for
> example with mod_passenger or Heroku.
>
> -- Matma Rex
> ___
> Camping-list mailing list
> Camping-list@rubyforge.org
> http://rubyforge.org/mailman/listinfo/camping-list
>
___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Re: run my Camping app as a Rack app

2011-10-09 Thread Bartosz Dziewoński
I'm not sure what are you trying to accomplish.

Can't you just create a config.ru file like this:
  require './yourapp.rb'
  run YourApp

And then use `rackup` to start the app?

config.ru files are widely understood, the same thing works for
example with mod_passenger or Heroku.

-- Matma Rex
___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list


run my Camping app as a Rack app

2011-10-09 Thread Nokan Emiro
Hi,

Could you please show me the preferred/nicest way
to run my Camping application as a Rack all?  I like
doing my work in Rack because it's easy to run my app
in a standalone webserver, or "mount" it to a path in
my production environment as a FastCGI app.

require 'rubygems'
require 'rack'
app = ...
Rack::Handler::FastCGI.run app, :Port => 

I use Camping as a proof-of-concept framework, but it's
time to turn some of my apps into production, and I'm looking
for the right way to do this, and I think this is to make it run
as a Rack app.  I've found code snippets on the net but
none of them worked.  This one is the less wrong one:

require 'rubygems'
require 'rack'
require 'camping'

Camping.goes :X
module X
# my Camping app here #
end

X.create

Rack::Handler::FastCGI.run X, :Port => 8899

I know it's not good.  Basicly my question is:  how to repair this? :)

I have two problems:

1) X.create makes ugly error messages
2) if I comment out the X.create line, it seems to work, but does
not really do.  It listens for connections on 8899, but it halt on
the first fcgi connection from the webserver.

thx,
uzlee
___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list