4

I've recently given in to temptation and bought a new MacBook - I've upgraded the RAM, got AppleCare etc. and am really enjoying myself! I've been setting up my development environment - compiling my own Apache (built in one is terrible, or so I've heard), PHP and getting everything set up the way I want to.

As I'm not using the default Apache, I wanted to know how I setup Apache, and other applications as daemons; running in the background, much like Windows' services.

I was wondering if any of you guys have any experience with this sort of stuff, and if you could give me a hand.

5
  • For what it's worth I haven't had any trouble with Leopard's built in Apache install. I'm just using it for development of course, but once I enabled PHP, turned on virtual hosts and tweaked a few other config files it's worked flawlessly. Much easier than trying to build everything from scratch. May 20, 2009 at 20:44
  • Are you asking about writing such programs, or installing one? May 20, 2009 at 20:45
  • Installing them - I want to be able to run programs (both .apps and compiled binaries) at runtime, and let them work in the background. I'm sure it's possible, just not sure how...
    – jamierumbelow
    May 20, 2009 at 20:49
  • Jamie, serverfault.com is a better place for this question. Re-ask it there and you should get a good answer. May 20, 2009 at 20:50
  • Is the serverfault beta open yet? Does he need an invite? Certainly the best place, but... May 20, 2009 at 21:08

5 Answers 5

6

OSX uses launchd to manage all daemon starting and stopping. If you google for "launchd" the first result is apple's article on how to use it (I would have just linked, but stackoverflow wont let me)

For what you're trying to do, I suggest you simply edit the already existing apache launchd file to point to your own binary. Then you can control it using the Sharing preference pane. The file is at /System/Library/LaunchDaemons/org.apache.httpd.plist

3

You need to use launchd, Apple's tool for managing all system processes. Launchd is a unified replacement for a whole slew of specialized unix utilities which managed different pieces of this (init, rc, etc, etc).

Apple covers some of this on their website, but they have a bunch of out-of-date documents mixed in which describe obsolete techniques. Dan Benjamin has a nicely written tutorial on how to install MySQL. This is a very well written guide which will teach you the general steps of installing unix/linux software on the Mac (without relying on MacPorts or Fink). Dan's MySQL tutorial goes through the creation of a launchd config file.

Basically, you'll create an xml configuration file (a plist file) which specifies the working directory, which user to run as, etc. You'll put that file in a particular directory and then tell launchd to load it, using launchctl.

He also has tutorials for setting up Ruby on Rails, which you might find useful, but I don't think that involves any daemons.

1
1

You'll want to look into using launchd. Look up that on Apple's website.

0

It's been a while...but I think you just need to add the command to start apache to /init/rc (it's the same as adding a service to other *nix based OSes).

0

I can't comment yet... You really should look at the Apple info on using launchd. There are choices relating to whether the daemon is started on demand (when an incoming TCP connection happens on a specified port) or run once at system startup, setting environment variables, what happens if it quits, whether to run it periodically, etc. There are a lot of possibilities, and best practices would be to learn what's there and make the best choice(s) for your particular application.

The Property List Editor (in /Developer/Applications/Utilities) is just fine for making and viewing plist files. I'm not sure, but you might need to have installed XCode (free from Apple) to have this tool.

You must log in to answer this question.