Sorry for the newbie question but I''m stumped: I have an app that requires sudo to run mongrel_rails. For my capistrano recipe is do it like this: sudo "mongrel_rails start -e production -p #{application_port} -d -c #{current_path}" Which works famously. Now I have tried several things for my restart task. Here they are: sudo "cd #{current_path} && sudo mongrel_rails restart" That doesn''t work. For some reason the "cd..." command does not work. I''m assuming that is some sort of problem with capistrano or my server. So moving on I tried: sudo "mongrel_rails restart -c #{current_path}" to avoid having to do the "cd...". When I do that I get this in my mongrel.log: ** USR2 signal received. ** Restarting with arguments: ruby /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13/bin/mongrel_rails start -e production -p 81 -d -c /Library/WebServer/rails/kd/current /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13/bin/mongrel_rails:158:in `exec'': Operation not supported - ruby /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13/bin/mongrel_rails start -e production -p 81 -d -c /Library/WebServer/rails/kd/current (Errno::EOPNOTSUPP) from /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13/bin/mongrel_rails:158:in `run'' from /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13/lib/mongrel/command.rb:188: in `run'' from /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13/bin/mongrel_rails:247 from /opt/local/bin/mongrel_rails:18 Which I assume is due to the "sudo" not being added to the "mongrel_rails start..." command that is being called by "mongrel_rails restart". So it seems that one cannot do "mongrel_rails restart" with "sudo". My ugly hack is to to "mongrel_rails stop" and then "mongrel_rails start". Any ideas? Now, I have control over this server and am fine with changing permissions so that I don''t have to use "sudo". This is probably off-topic for this list (better suited to "Server Admin for Dummies" perhaps) but how do I do that? I assume I need sudo because mongrel needs to write stuff to a tmp dir that my user does not have access to. Any pointers? Thanks, Tom
"cd" does not respond to the sudo command. So separate the command into two lines, like so: run "cd #{current_path}" sudo "mongrel_rails restart" --Alison http://blog.alisonrowland.com On Jun 16, 2006, at 11:25 AM, Tom Brice wrote:> Sorry for the newbie question but I''m stumped: > > I have an app that requires sudo to run mongrel_rails. For my > capistrano > recipe is do it like this: > > sudo "mongrel_rails start -e production -p #{application_port} -d -c > #{current_path}" > > Which works famously. > > Now I have tried several things for my restart task. Here they are: > > sudo "cd #{current_path} && sudo mongrel_rails restart" > > That doesn''t work. For some reason the "cd..." command does not > work. I''m > assuming that is some sort of problem with capistrano or my > server. So > moving on I tried: > > sudo "mongrel_rails restart -c #{current_path}" > > to avoid having to do the "cd...". When I do that I get this in my > mongrel.log: > > ** USR2 signal received. > ** Restarting with arguments: ruby > /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13/bin/mongrel_rails > start -e > production -p 81 -d -c /Library/WebServer/rails/kd/current > /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13/bin/mongrel_rails: > 158:in > `exec'': Operation not supported - ruby > /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13/bin/mongrel_rails > start -e > production -p 81 -d -c /Library/WebServer/rails/kd/current > (Errno::EOPNOTSUPP) > from > /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13/bin/mongrel_rails: > 158:in > `run'' > from > /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13/lib/mongrel/ > command.rb:188: > in `run'' > from > /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13/bin/mongrel_rails:247 > from /opt/local/bin/mongrel_rails:18 > > Which I assume is due to the "sudo" not being added to the > "mongrel_rails > start..." command that is being called by "mongrel_rails restart". > So it > seems that one cannot do "mongrel_rails restart" with "sudo". My > ugly hack > is to to "mongrel_rails stop" and then "mongrel_rails start". Any > ideas? > > Now, I have control over this server and am fine with changing > permissions > so that I don''t have to use "sudo". This is probably off-topic for > this > list (better suited to "Server Admin for Dummies" perhaps) but how > do I do > that? I assume I need sudo because mongrel needs to write stuff to > a tmp > dir that my user does not have access to. Any pointers? > > Thanks, > Tom > > > _______________________________________________ > Mongrel-users mailing list > Mongrel-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-users
On 6/16/06 10:29 AM, Alison Rowland wrote:> two lines, like so: > > run "cd #{current_path}" > sudo "mongrel_rails restart"Thanks Alison. I though I tried this but I just rechecked. Problem is capistrano. When I try this the cd executes but doesn''t "hold". This means that my mongrel_rails restart command is executed in my home dir (not my RAILS_ROOT). It doesn''t find the PID file so it fails. Any other ideas? Tom
On 6/16/06 10:47 AM, Tom Brice wrote:> On 6/16/06 10:29 AM, Alison Rowland wrote: > >> two lines, like so: >> >> run "cd #{current_path}" >> sudo "mongrel_rails restart" > > Thanks Alison. > > I though I tried this but I just rechecked. Problem is capistrano. When I > try this the cd executes but doesn''t "hold". This means that my mongrel_rails > restart command is executed in my home dir (not my RAILS_ROOT). It doesn''t > find the PID file so it fails. > > Any other ideas? > > TomAlso just checked doing this at the server (to take capistrano out of the equation): sudo mongrel_rails restart Still gives me the failure because the mongrel_rails start command executed by mongrel_rails restart does not "inherit" sudo privileges. So same error trace as my original message. Tom
On 6/16/06, Tom Brice <tom at onidle.com> wrote:> > Sorry for the newbie question but I''m stumped: > > sudo "cd #{current_path} && sudo mongrel_rails restart" > > That doesn''t work.Not having worked with capistrano (yet! I will better myself one day!) I really shouldn''t advice you, but here goes: ''cd'', as you note, doesn''t "hold" since it affects the process it runs in, and I assume that capistrano''s sudo either splits your command in two, running them in two different, consecutive processes, or just sends it along, in which case the system''s sudo doesn''t handle && very well. But I assume that you have the full power of Ruby in capistrano, so you could try Dir.chdir(current_path) sudo "mongrel_rails restart" making sure to chdir back if you need to. If that doesn''t work, how about putting your commands in a shell script and running that: -----------script.sh-------- #!/bin/sh cd whatever mongrel_rails restart -----------end script.sh---- with a sudo "/path/to/script.sh" I haven''t tried it, but it should be worth a shot. Good luck, /David -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20060616/054e124f/attachment.htm
I don''t know what''s going on with your restart task failing. You should probably fix that before worrying about Capistrano, but in the event that you get it working, here''s a bit more Cap info. I just looked at my deploy.rb, and it has a little extra bit of structure which may help. Here''s my whole restart task, which I originally grabbed from somebody''s snippets: desc "Restart the web server" task :restart, :roles => :app do begin run "cd #{current_path}" sudo "mongrel_cluster_ctl restart" rescue RuntimeError => e puts e puts "Probably not a big deal, so I''ll just keep trucking..." end end Perhaps wrapping it in begin...rescue...end lets Capistrano know to execute it all as one thing. --Alison http://blog.alisonrowland.com On Jun 16, 2006, at 11:47 AM, Tom Brice wrote:> On 6/16/06 10:29 AM, Alison Rowland wrote: > >> two lines, like so: >> >> run "cd #{current_path}" >> sudo "mongrel_rails restart" > > Thanks Alison. > > I though I tried this but I just rechecked. Problem is > capistrano. When I > try this the cd executes but doesn''t "hold". This means that my > mongrel_rails restart command is executed in my home dir (not my > RAILS_ROOT). It doesn''t find the PID file so it fails. > > Any other ideas? > > Tom > > > _______________________________________________ > Mongrel-users mailing list > Mongrel-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-users
The implementation of ''sudo'' in capistrano is a little flawed. It ought to wrap the command in a ''sh -c'' wrapper to make sure that the sudo privileges apply to the entire command string and not just the first command. At the moment you have to do that manually. To do what you want do this sudo <<-CMD sh -c "cd #{current_path} && mongrel_rails start" CMD The other problem is that capistrano is a little quick of the mark when shutting down a connection - often before the last program has had a chance to catch HUP signals. If this happens use. sudo <<-CMD sh-c "cd #{current_path} && nohup mongrel_rails start >/dev/null" CMD Rgs NeilW -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20060616/fc8ffc24/attachment.htm
On 6/16/06 11:20 AM, Neil Wilson wrote:> To do what you want do this > > sudo <<-CMD > sh -c "cd #{current_path} && mongrel_rails start" > CMDThanks. This still has the same problem with sudo not applying to the mongrel_rails start command that mongrel_rails restart sends after sending the USR2 signal. I''m having other difficulties with Apache and file uploads. I''m gonna try mongrel_cluster to see how that works. Thanks to everyone for the suggestions. At least I learned something! Tom
On Fri, 2006-06-16 at 16:20 -0500, Tom Brice wrote:> On 6/16/06 11:20 AM, Neil Wilson wrote: > > > To do what you want do this > > > > sudo <<-CMD > > sh -c "cd #{current_path} && mongrel_rails start" > > CMD > > Thanks. This still has the same problem with sudo not applying to the > mongrel_rails start command that mongrel_rails restart sends after sending > the USR2 signal. > > I''m having other difficulties with Apache and file uploads. I''m gonna try > mongrel_cluster to see how that works. > > Thanks to everyone for the suggestions. At least I learned something!Tom, mongrel_cluster is the way to go for deployments with capistrano. If you can post the stack dump you get in your mongrel.log after you do this restart then I can probably see why it''s failing. -- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/
On 6/16/06 4:40 PM, Zed Shaw wrote:> Tom, mongrel_cluster is the way to go for deployments with capistrano. > If you can post the stack dump you get in your mongrel.log after you do > this restart then I can probably see why it''s failing.Here''s what I get: ** USR2 signal received. ** Restarting with arguments: ruby /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13/bin/mongrel_rails start -e production -p 81 -d -c /Library/WebServer/rails/kd/current /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13/bin/mongrel_rails:158:in `exec'': Operation not supported - ruby /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13/bin/mongrel_rails start -e production -p 81 -d -c /Library/WebServer/rails/kd/current (Errno::EOPNOTSUPP) from /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13/bin/mongrel_rails:158:in `run'' from /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13/lib/mongrel/command.rb:188: in `run'' from /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13/bin/mongrel_rails:247 from /opt/local/bin/mongrel_rails:18 I''m gonna try to do mongrel_cluster right now. Thanks, Tom
I don''t get the same problem on Ubuntu linux using the same commands. Are you using Solaris? Looks to me like exec is not holding root identity, which may mean that sudo is only setting the Effective UID and not the real one. Can you try this sudo ruby -e ''puts Process.euid; puts Process.uid'' and see if you get two zeroes. NeilW On 16/06/06, Tom Brice <tom at onidle.com> wrote:> > On 6/16/06 4:40 PM, Zed Shaw wrote: > > > Tom, mongrel_cluster is the way to go for deployments with capistrano. > > If you can post the stack dump you get in your mongrel.log after you do > > this restart then I can probably see why it''s failing. > > Here''s what I get: >-- Neil Wilson (neil at aldur.co.uk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20060617/ebc3245b/attachment.htm
And while you''re at it try this as well. sudo ruby -e ''exec "ruby -e \"puts Process.euid; puts Process.uid\""'' NeilW -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20060617/3b292928/attachment.htm
On 6/17/06 1:30 AM, Neil Wilson wrote:> Can you try this > > sudo ruby -e ''puts Process.euid; puts Process.uid'' > > and see if you get two zeroes.SSH''d into my server I get this: % sudo ruby -e ''puts Process.euid; puts Process.uid'' Password: 0 0 On 6/17/06 1:35 AM, Neil Wilson wrote:> And while you''re at it try this as well. > > sudo ruby -e ''exec "ruby -e \"puts Process.euid; puts Process.uid\""'' > > NeilWI get: % sudo ruby -e ''exec "ruby -e \"puts Process.euid; puts Process.uid\""'' 0 0 I''m now using mongrel_cluster and it''s cap tasks are starting the server as my user (thus not requiring sudo). The mongrel_cluster restart seems to work as well. I''m still a bit baffled about the sudo on this machine. I had to set :use_sudo, FALSE for cap -a configure_mongrel_cluster. The server is a Xserve running OS X Server 10.4.5. Tom
Looks like its not permissions then. Thinking about it I''d have expected EPERM rather than EOPNOTSUPP. Are you still getting the mongrel cluster to use port 81, or are the ports now above 1024? NeilW
On 6/18/06 1:22 PM, Neil Wilson wrote:> Are you still getting the mongrel cluster to use port 81, or are the ports > now above 1024?I''m using 4 mongrels starting at 8000 for the cluster. The errors I had previously were one mongrel (mongrel_rails start ... No mongrel_cluster) which required sudo. Now that I''m using mongrel_cluster the mongrels start under my user and do not require sudo. Seems like :use_sudo defaulting to TRUE in Capistrano did not work for some commands on my server. Particularly anything that involved more than one command. One-liners execute sudo as expected, mulitple commands do not. Let me know if you have any suggestions as I''m keen to understand the system. That said, for now I''m running. Thanks for your help, Tom
Does the one mongrel work if you use -p 8000 rather than -p 81 and ''run'' rather than sudo (or setting use_sudo to false which has the same effect)? Port 81 is a privileged port, and port 8000 isn''t you see. NeilW
Seemingly Similar Threads
- problem restarting mongrel_cluster outside RAILS_ROOT - patch and other option
- Deploying to a staging server using Capistrano: how to start up BackgrounDRb?
- Getting /etc/mongrel_cluster and startup script to work?
- mongrel_rails hang and does not respond
- Log problem on stop/restart