tags:

views:

51

answers:

0

I'm having trouble getting unicorn to launch correctly using launchctl. I have a Rails application on my macbook pro. It runs fine under Passenger, but I'd like to switch over to unicorn to test it out.

I have the following unicorn.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
                       "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
<plist version="1.0">
  <dict>
    <key>Label</key><string>unicorn</string>
    <key>EnvironmentVariables</key>
    <dict>
      <key>GEM_HOME</key><string>/Users/me/.rvm/gems/ruby-1.8.7-p299@myapp</string>
    </dict>
    <key>Program</key><string>/Users/me/.rvm/gems/ruby-1.8.7-p299@myapp/bin/unicorn_rails</string>
    <key>ProgramArguments</key>
    <array>
      <string>-c</string>
      <string>/Users/me/Projects/myapp/unicorn.rb</string>
      <string>-E</string>
      <string>development</string>
      <string>-D</string>
    </array>
    <key>KeepAlive</key><true/>
    <key>StandardErrorPath</key><string>/var/log/unicorn/unicorn.stderr.log</string>
    <key>LaunchOnlyOnce</key><true/>
  </dict>
</plist>

and my unicorn.rb is as follows:

worker_processes 2
working_directory "/Users/sax/Projects/myapp/"

# This loads the application in the master process before forking
# worker processes
# Read more about it here:
# http://unicorn.bogomips.org/Unicorn/Configurator.html
preload_app true

timeout 30

user 'sax', 'staff'
# This is where we specify the socket.
# We will point the upstream Nginx module to this socket later on
listen "/var/tmp/unicorn.sock", :backlog => 64

pid "/var/tmp/unicorn.pid"

# Set the path of the log files inside the log folder of the testapp
stderr_path "/var/log/unicorn/unicorn.stderr.log"
stdout_path "/var/log/unicorn/unicorn.stdout.log"

before_fork do |server, worker|
# This option works in together with preload_app true setting
# What is does is prevent the master process from holding
# the database connection
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|
# Here we are establishing the connection after forking worker
# processes
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end

After changing permissions on some directories, I can get unicorn to run.

launchctl load ~/Library/LaunchAgents/unicorn.plist

The log file goes in the correct place (specified in the plist), but the pid file goes into /tmp/pids. When I ps -ax | grep unicorn it looks like it's running on port 8080. I can't find a socket file anywhere.

So my assumption is that unicorn_rails is not paying attention to directives in the configation file.

Has anyone seen this problem before and found a solution?