Google Groups Home
Help | Sign in
Trying to use Thin with Nginx and Capistrano
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  14 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
pikz  
View profile
 More options May 11, 5:58 am
From: pikz <pik...@gmail.com>
Date: Sun, 11 May 2008 02:58:41 -0700 (PDT)
Local: Sun, May 11 2008 5:58 am
Subject: Trying to use Thin with Nginx and Capistrano
I don't have very much experience using these tools, but I'm trying to
run Thin now instead of Mongrel. What I want to do is to be able to
start the Rails application when I reboot the VPS and I also want it
to (re)start when I deploy it with Capistrano.

I have deployed the application previously so in the application root
directory three are three directories: current, releases and shared.

My first question is: Can I run the application manually in some way?
Right now if I go to the /current directory and run 'thin start' then
it doesn't work.

Question two: How can I make the application start correctly at
reboot?
I ran a command similar to this one: 'sudo thin config -C /etc/thin/
testapp.yml -c /home/demo/public_html/testapp/current  --servers 2 -p
5000 -e development'. This then created the .YML file, but I'm not
sure if this is supposed to work with the deployed app with its
directory structure (current, releases, shared).

Note: I also ran: 'sudo /usr/sbin/update-rc.d -f thin defaults'.

I edited the YML file and changed the address to 127.0.0.1 and I
edited the Nginx vhost file to match this with ports 5000 and 5001:

upstream domain {
        server 127.0.0.1:5000;
        server 127.0.0.1:5001;
    }

I haven't been able to access the application through the browser with
this setup.

Question three: My current Capistrano setup has a script/spin file
containing something like this: '/home/demo/public_html/testapp/
current/script/process/spawner -p 8000 -i 2 -e development'. What
should this file contain now that I want to run Thin when deploying
the app?

Thanks a lot in advance.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adam Byrtek  
View profile
 More options May 12, 5:47 pm
From: "Adam Byrtek" <adambyr...@gmail.com>
Date: Mon, 12 May 2008 23:47:45 +0200
Local: Mon, May 12 2008 5:47 pm
Subject: Re: Trying to use Thin with Nginx and Capistrano

On Sun, May 11, 2008 at 11:58 AM, pikz <pik...@gmail.com> wrote:
>  Right now if I go to the /current directory and run 'thin start' then
>  it doesn't work.

This should work - please provide the output this command gives you.

>  Question two: How can I make the application start correctly at
>  reboot?

You have to have a startup script to run your application after reboot.

>  I ran a command similar to this one: 'sudo thin config -C /etc/thin/
>  testapp.yml -c /home/demo/public_html/testapp/current  --servers 2 -p
>  5000 -e development'. This then created the .YML file, but I'm not
>  sure if this is supposed to work with the deployed app with its
>  directory structure (current, releases, shared).

This directory structure is not really special. Most of the times you
are interested only with "current", which is symlinked to the latest
release. This is a standard Rails application dir, the only difference
is that some subdirectories are symlinked to a shared location.

>  Note: I also ran: 'sudo /usr/sbin/update-rc.d -f thin defaults'.

Do you use Debian? What was the output of this command? If you don't
have /etc/init.d/thin startup script this command will have no effect.

>  I edited the YML file and changed the address to 127.0.0.1 and I
>  edited the Nginx vhost file to match this with ports 5000 and 5001:

Start with simple things - if you can't access one Thin instance,
configuring a cluster doesn't make much sense.

Regards,
Adam

--
Adam Byrtek | Alpha
http://www.adambyrtek.net
http://www.codesprinters.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
macournoyer  
View profile
(1 user)  More options May 12, 7:50 pm
From: macournoyer <macourno...@gmail.com>
Date: Mon, 12 May 2008 16:50:42 -0700 (PDT)
Local: Mon, May 12 2008 7:50 pm
Subject: Re: Trying to use Thin with Nginx and Capistrano
You need to run:

 sudo thin install

to setup the startup script /etc/init.d/thin

To restart when you deploy, simply override the deploy:restart cap
recipe.

Let me know if this doesn't work

On May 12, 5:47 pm, "Adam Byrtek" <adambyr...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
pikz  
View profile
 More options May 13, 2:33 am
From: pikz <pik...@gmail.com>
Date: Mon, 12 May 2008 23:33:17 -0700 (PDT)
Local: Tues, May 13 2008 2:33 am
Subject: Re: Trying to use Thin with Nginx and Capistrano
Hi. Thank you for taking the time to answer my questions.

The output when I run 'thin start' in the /current directory is this:

>> Using rails adapter

/home/demo/public_html/testapp/releases/20080507203211/config/../
vendor/rails/railties/lib/initializer.rb:506:in `read': No such file
or directory - /home/demo/public_html/testapp/releases/20080507203211/
config/database.yml (Errno::ENOENT)
        from /home/demo/public_html/testapp/releases/20080507203211/
config/../vendor/rails/railties/lib/initializer.rb:506:in
`database_configuration'
        from /home/demo/public_html/testapp/releases/20080507203211/
config/../vendor/rails/railties/lib/initializer.rb:233:in
`initialize_database'
        from /home/demo/public_html/testapp/releases/20080507203211/
config/../vendor/rails/railties/lib/initializer.rb:94:in `process'
        from /home/demo/public_html/testapp/releases/20080507203211/
config/../vendor/rails/railties/lib/initializer.rb:49:in `send'
        from /home/demo/public_html/testapp/releases/20080507203211/
config/../vendor/rails/railties/lib/initializer.rb:49:in `run'
        from /home/demo/public_html/testapp/releases/20080507203211/
config/environment.rb:13
        from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:
27:in `gem_original_require'
        from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:
27:in `require'
         ... 8 levels...
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/runner.rb:
136:in `run!'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/bin/thin:6
        from /usr/bin/thin:19:in `load'
        from /usr/bin/thin:19

I guess this would also prevent it from running at reboot then. It
mentioned the database.yml file. The database.yml file is located in /
shared/config/

This applications works when I run this command: /home/demo/
public_html/testapp/
current/script/process/spawner -p 8000 -i 2 -e development

Thanks.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
pikz  
View profile
 More options May 13, 2:55 am
From: pikz <pik...@gmail.com>
Date: Mon, 12 May 2008 23:55:31 -0700 (PDT)
Local: Tues, May 13 2008 2:55 am
Subject: Re: Trying to use Thin with Nginx and Capistrano

> To restart when you deploy, simply override the deploy:restart cap
> recipe.

Thank you for your answer. Wouldn't this try to start mongrel instead
if I don't edit the script/spin in any way first?

When I run cap deploy:restart then I get:

* executing `deploy:restart'
  * executing "/home/demo/public_html/testapp/current/script/process/
reaper"
    servers: ["domain"]
Password:
    [domain] executing command
*** [err :: domain] Couldn't find any pid file in '/home/demo/
public_html/testapp/releases/20080507203211/tmp/pids' matching
'dispatch.[0-9]*.pid'
*** [err :: domain]
*** [err :: domain] (also looked for processes matching "/home/demo/
public_html/testapp/releases/20080507203211/public/dispatch.fcgi")
*** [err :: domain]
    command finished


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adam Byrtek  
View profile
 More options May 13, 4:13 am
From: "Adam Byrtek" <adambyr...@gmail.com>
Date: Tue, 13 May 2008 10:13:19 +0200
Local: Tues, May 13 2008 4:13 am
Subject: Re: Trying to use Thin with Nginx and Capistrano

On Tue, May 13, 2008 at 8:33 AM, pikz <pik...@gmail.com> wrote:
>  I guess this would also prevent it from running at reboot then. It
>  mentioned the database.yml file. The database.yml file is located in /
>  shared/config/

The answer is obvious, as the error message says, you don't have the
current/config/database.yml file. It is not symlinked automatically
from shared, you have to include an extra Capistrano task to do this,
here is mine:

  desc "Copy database config"
  task :after_update_code, :roles => :app do
    db_config = "#{shared_path}/config/database.yml"
    run "cp #{db_config} #{release_path}/config/database.yml"
  end

>  This applications works when I run this command: /home/demo/
>  public_html/testapp/

Looks like you have the database config file there.

Regards,
Adam

--
Adam Byrtek | Alpha
http://www.adambyrtek.net
http://www.codesprinters.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
pikz  
View profile
 More options May 13, 10:45 am
From: pikz <pik...@gmail.com>
Date: Tue, 13 May 2008 07:45:21 -0700 (PDT)
Local: Tues, May 13 2008 10:45 am
Subject: Re: Trying to use Thin with Nginx and Capistrano
Thank you. I understand now about the database.yml symlink thing.

Do you have any idea why I get an error when trying to run 'cap
deploy:restart'?

Is it okay to just add this to script/spin: /etc/init.d thin restart

On May 13, 11:13 am, "Adam Byrtek" <adambyr...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
macournoyer  
View profile
 More options May 13, 11:26 am
From: macournoyer <macourno...@gmail.com>
Date: Tue, 13 May 2008 08:26:42 -0700 (PDT)
Local: Tues, May 13 2008 11:26 am
Subject: Re: Trying to use Thin with Nginx and Capistrano
You don't need to use the script/spin, I think this is legacy from
FastCGI deployment.

All you need to run in your cap task is: thin restart -C your/config/
file.yml

Here's the recipe I use:
====

in config/deploy.rb:
--------------------
set :thin, {
  :environment => 'production',
  :user        => 'deploy',
  :port        => 5000,
  :group       => 'www-data',
  :servers     => 2,

}

in lib/recipes/thin.rb:
-----------------------
namespace :deploy do
  def thin_cluster(command)
    cmd = "thin #{command} "
    cmd << "-c#{current_path} "
    cmd << "-e#{thin[:environment]} "
    cmd << "-s#{thin[:servers]} "
    cmd << "-u#{thin[:user]} "
    cmd << "-g#{thin[:group]} "
    cmd << "--max-conns 4096 "
    cmd << "--max-persistent-conns 500 "
    sudo cmd, :as => 'root'
  end

  desc 'Start Thin processes on the app server.'
  task :start, :roles => :app do
    thin_cluster :start
  end

  desc 'Stop the Thin processes on the app server.'
  task :stop, :roles => :app do
    thin_cluster :stop
  end

  desc 'Restart the Thin processes on the app server by starting and
stopping the cluster.'
  task :restart, :roles => :app do
    thin_cluster :restart
  end
end

===========
Note that you only need to run thin w/ sudo if you set max-conns
higher then 1024.

On May 13, 10:45 am, pikz <pik...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
pikz  
View profile
 More options May 15, 6:52 am
From: pikz <pik...@gmail.com>
Date: Thu, 15 May 2008 03:52:23 -0700 (PDT)
Local: Thurs, May 15 2008 6:52 am
Subject: Re: Trying to use Thin with Nginx and Capistrano
Thanks. I got it working now by adding this:

...
task :restart do
  sudo "thin restart -C /your/config/file.yml"
end
...

I tried without sudo also by replacing sudo with run, but this didn't
work for me, but I'm not experienced with Capistrano so I might have
done it wrong. But it works well with sudo, so that's good.

Thanks a lot for your help here. I appreciate it!


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
pikz  
View profile
 More options May 16, 10:21 am
From: pikz <pik...@gmail.com>
Date: Fri, 16 May 2008 07:21:20 -0700 (PDT)
Local: Fri, May 16 2008 10:21 am
Subject: Re: Trying to use Thin with Nginx and Capistrano
Actually, I learned that it's better to run web apps as a normal user
instead of using sudo. So I would like to learn how to do this. Can
you help me with this?

Currently when I type 'thin restart -C /your/config/file.yml' without
sudo then I get this:

Stopping server on 127.0.0.1:8000 ...
Sending QUIT signal to process 4469 ...
/usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/daemonizing.rb:121:in
`kill': Operation not permitted (Errno::EPERM)
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/
daemonizing.rb:121:in `send_signal'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/
daemonizing.rb:96:in `kill'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/
controllers/controller.rb:86:in `stop'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/
controllers/controller.rb:123:in `tail_log'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/
controllers/controller.rb:85:in `stop'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/runner.rb:
166:in `send'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/runner.rb:
166:in `run_command'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/runner.rb:
136:in `run!'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/bin/thin:6
        from /usr/bin/thin:19:in `load'
        from /usr/bin/thin:19
Stopping server on 127.0.0.1:8001 ...
Sending QUIT signal to process 4474 ...
/usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/daemonizing.rb:121:in
`kill': Operation not permitted (Errno::EPERM)
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/
daemonizing.rb:121:in `send_signal'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/
daemonizing.rb:96:in `kill'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/
controllers/controller.rb:86:in `stop'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/
controllers/controller.rb:123:in `tail_log'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/
controllers/controller.rb:85:in `stop'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/runner.rb:
166:in `send'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/runner.rb:
166:in `run_command'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/runner.rb:
136:in `run!'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/bin/thin:6
        from /usr/bin/thin:19:in `load'
        from /usr/bin/thin:19
Starting server on 127.0.0.1:8000 ...
/usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/daemonizing.rb:150:in
`remove_stale_pid_file': tmp/pids/thin.8000.pid already exists, seems
like it's already running (process ID: 4469). Stop the process or
delete tmp/pids/thin.8000.pid. (Thin::PidFileExist)
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/
daemonizing.rb:40:in `daemonize'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/
controllers/controller.rb:54:in `start'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/runner.rb:
166:in `send'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/runner.rb:
166:in `run_command'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/runner.rb:
136:in `run!'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/bin/thin:6
        from /usr/bin/thin:19:in `load'
        from /usr/bin/thin:19
Starting server on 127.0.0.1:8001 ...
/usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/daemonizing.rb:150:in
`remove_stale_pid_file': tmp/pids/thin.8001.pid already exists, seems
like it's already running (process ID: 4474). Stop the process or
delete tmp/pids/thin.8001.pid. (Thin::PidFileExist)
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/
daemonizing.rb:40:in `daemonize'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/
controllers/controller.rb:54:in `start'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/runner.rb:
166:in `send'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/runner.rb:
166:in `run_command'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/lib/thin/runner.rb:
136:in `run!'
        from /usr/lib/ruby/gems/1.8/gems/thin-0.8.1/bin/thin:6
        from /usr/bin/thin:19:in `load'
        from /usr/bin/thin:19

It works when I run it with sudo. Max-conns is set to 1024 in the YML-
file.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adam Byrtek  
View profile
 More options May 16, 12:06 pm
From: "Adam Byrtek" <adambyr...@gmail.com>
Date: Fri, 16 May 2008 18:06:46 +0200
Local: Fri, May 16 2008 12:06 pm
Subject: Re: Trying to use Thin with Nginx and Capistrano

On Fri, May 16, 2008 at 4:21 PM, pikz <pik...@gmail.com> wrote:
> It works when I run it with sudo. Max-conns is set to 1024 in the YML-
> file.

Don't do restart, just stop the old server you started as root and
start a new one as an unprivileged user.

Regards,
Adam

--
Adam Byrtek | Alpha
http://www.adambyrtek.net
http://www.codesprinters.com


    Reply to author    Forward