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?
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.
> 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.
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
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.
> 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.
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:
> 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:
> > 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.
...
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.
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.