Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

For example, when the server boots I need to start Tomcat, and I need to start an Android emulator, and then issue some commands to it. These are on the path already. I'm familiar with Linux and understand the basics of Daemons, and I suspect it will be something similar?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

LaunchDaemons are the preferred way to do this in OS X. Each daemon is controlled by a .plist file in /Library/LaunchDaemons (for add-on daemons; the builtin daemons are in /System/Library/LaunchDaemons) which specifies when to start the daemon (e.g. on load, when a connection is received on a TCP port, at certain times, etc), what command and arguments to use to start the daemon, etc. See the Apple developer docs here, and look in /System/Library/LaunchDaemons for examples.

One big warning if you're used to using other startup systems: by default, launchd expects programs it starts to not daemonize themselves. This page suggests starting Tomcat with a launchd plist named /Library/LaunchDaemons/org.apache.tomcat.plist containing:

<?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>org.apache.tomcat</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Library/Tomcat/Home/bin/catalina.sh</string>
        <string>run</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

(Note that catalina.sh is told to "run", not "start".)

If you need to launch something that cannot be prevented from daemonizing, you'll need to add something like this to the .plist:

<key>KeepAlive</key>
<false/>
<key>AbandonProcessGroup</key>
<true/>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.