Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7020309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:18:07+00:00 2026-05-27T23:18:07+00:00

i’m currently using rvm and unicorn for server management under osx lion. i also

  • 0

i’m currently using rvm and unicorn for server management under osx lion.
i also use a gemset.

so for starting my server i do following:

cd /xyz/project
unicorn -c /xyz/project/config/unicorn.rb -E production

now i want this server starting when my computer starts up.
i read something about adding a plist file to ~/Library/LaunchAgents/ and activating it with launchctl but i have no idea what to write inside this plist file for starting my server.

any ideas? also i think it’s difficult, because the gemset needs to get activated by cd’ing into this dir.

thanks for all help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:18:08+00:00Added an answer on May 27, 2026 at 11:18 pm

    You probably want to run this as a LaunchDaemon, not a LaunchAgent. Daemons run in system context, and can therefore run at system startup, before anyone’s logged in. Agents run inside login sessions, and therefore don’t start until a user logs in (and run as the user not as root, and if two users log in at once with fast switching they’ll run a copy for each user, and…). The .plist file itself is pretty much the same for daemons vs. agents, the difference is whether you put it in /Library/LaunchDaemons or /Library/LaunchAgents.

    The file itself depends on a few things. I’m assuming it needs to be started at system boot. Does it daemonize itself (i.e. drop into the background)? launchd doesn’t like the programs it launches to daemonize themselves, as it wants to be able to monitor them and maybe restart them if they crash/exit. If unicorn has an option to not daemonize, use that; if not, you need to change the .plist file a bit to adapt to it. First, here’s a basic run-at-startup LaunchDaemon .plist file:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
            <key>Disabled</key>
            <false/>
            <key>Label</key>
            <string>local.unicorn</string>
            <key>ProgramArguments</key>
            <array>
                    <string>/full/path/to/unicorn</string>
                    <string>-c</string>
                    <string>/xyz/project/config/unicorn.rb</string>
                    <string>-E</string>
                    <string>production</string>
            </array>
            <key>WorkingDirectory</key>
            <string>/xyz/project</string>
            <key>RunAtLoad</key>
            <true/>
            <key>EnableTransactions</key>
            <false/>
    </dict>
    </plist>
    

    If unicorn daemonizes itself, you’ll need to add this (before the </dict> line):

            <key>KeepAlive</key>
            <false/>
            <key>AbandonProcessGroup</key>
            <true/>
    

    If it doesn’t daemonize (or you can get it to skip daemonizing by changing the ProgramArguments), you can optionally add this instead:

            <key>KeepAlive</key>
            <true/>
    

    Name the file something like /Library/LaunchDaemons/local.unicorn.plist (the name should match the label), set the ownership to root:wheel, and the permissions to 600. You can activate it with sudo launchctl load /Library/LaunchDaemons/local.unicorn.plist, or by rebooting.

    EDIT: for troubleshooting, you can add something like this to the .plist file:

            <key>StandardOutPath</key>
            <string>/tmp/unicorn.out</string>
            <key>StandardErrorPath</key>
            <string>/tmp/unicorn.err</string>
            <key>Debug</key>
            <true/>
    

    Then unload (sudo launchctl unload /Library/LaunchDaemons/local.unicorn.plist) and reload it, and check /var/log/system.log, /tmp/unicorn.out, and /tmp/unicorn.err for hints about what’s going wrong.

    EDIT2: to run as a different user, add something like:

            <key>UserName</key>
            <string>choise</string>
    

    EDIT3: I’m not very familiar with rvm and how it handles its configuration, but it sounds like you need to set some environment variables to set it up properly. Since you aren’t cd’ing into the directory in a regular shell, the .rvmrc file never gets run. There are several ways to solve this.

    First, you can figure out what environment variables need to be set, and add those to the .plist file with something like this:

            <key>EnvironmentVariables</key>
            <array>
                    <key>ruby_string</key>
                    <string>ruby-1.9.2-p136</string>
                    <key>gemset_name</key>
                    <string>unicorn</string>
            </array>
    

    …but that may be a little fragile, especially if they ever change; you’d need to update both the .rvmrc and .plist files together for it to work consistently.

    It might be better to have it actually open a shell and source all of the necessary setup files before launching unicorn. You could do this with a shell script, or just by including the necessary command sequence as a (single long) parameter to the shell. To do this, replace the ProgramArguments section with something like this:

            <key>ProgramArguments</key>
            <array>
                    <string>/bin/bash</string>
                    <string>-c</string>
                    <string>source /etc/rvmrc; source /Users/server/.rvmrc; source .rvmrc; /Users/server/.rvm/gems/ruby-1.9.2-head@q/bin/unicorn -c /Users/server/Sites/Rails/q/config/unicorn.rb -E production</string>
            </array>
    

    (but leave out sourceing any of the rvmrc files that don’t exist.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.