# Launchd, mongrel, capistrano, sudo hookup for Mac OS X

**URL:** <https://www.ruby-forum.com/t/launchd-mongrel-capistrano-sudo-hookup-for-mac-os-x/121900>\
**Category:** Rails\
**Created:** [December 2, 2007, 5:35pm UTC](https://www.ruby-forum.com/t/launchd-mongrel-capistrano-sudo-hookup-for-mac-os-x/121900 "2007-12-02T17:35:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [December 2, 2007, 5:35pm UTC](https://www.ruby-forum.com/t/launchd-mongrel-capistrano-sudo-hookup-for-mac-os-x/121900/1 "2007-12-02T17:35:55Z")

</div>

I won’t bore you with the details of how and why. I have my mongrels  
running under the “apache” user id.

In /Library/LaunchDaemons (on the server) create files called  
org.rubyforge.mongrel.8000 org.rubyforge.mongrel.8001, etc. One such  
file looks like this:

\<?xml version="1.0" encoding="UTF-8"?\> Label org.rubyforge.mongrel.8000 OnDemand WorkingDirectory /usr/local/www/rcm.easesoftware.com/rails/current StandardErrorPath log/mongrel.8000.log UserName apache GroupName daemon ProgramArguments /usr/local/bin/mongrel\_rails start -e production -p 8000 RunAtLoad 

Note that you want to change the WorkingDirectory. The 8000’s change to  
8001, etc for each of the files.

To get so that the apache user can control the mongrels, add this to  
/etc/sudoers (on the server):

apache ALL=(root) NOPASSWD: /bin/launchctl unload  
/Library/LaunchDaemons/org.rubyforge.mongrel.\*  
apache ALL=(root) NOPASSWD: /bin/launchctl load  
/Library/LaunchDaemons/org.rubyforge.mongrel.\*

To get so that capistrano can control this remotely, my Cap file has  
this in it:

namespace :deploy do  
desc “The start task is used by :cold\_deploy to start the application  
up”  
task :start, :roles =\> :app do  
run “sudo /bin/launchctl load  
/Library/LaunchDaemons/org.rubyforge.mongrel.\*”  
end

desc “Restart the mongrel cluster”  
task :restart, :roles =\> :app do  
run “sudo /bin/launchctl unload  
/Library/LaunchDaemons/org.rubyforge.mongrel._"  
run "sudo /bin/launchctl load  
/Library/LaunchDaemons/org.rubyforge.mongrel._”  
end

desc “Stop the mongrel cluster”  
task :stop, :roles =\> :app do  
run “sudo /bin/launchctl unload  
/Library/LaunchDaemons/org.rubyforge.mongrel.\*”  
end

desc “Hook to set up database.yml”  
task :after\_update\_code, :roles =\> :app do  
db\_config = “#{shared\_path}/config/database.yml.production”  
run “cp #{db\_config} #{release\_path}/config/database.yml”  
end  
end

HTH,  
pedz
