Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to create launchd.plist file for an httpd server. Problem is - when the httpd is run as privileged user it daemonizes, which is not allowed by launchd.plist manual page. If I don't run it as superuser - it cannot bind to privileged port (which is not necessary, but nice to have).

Question - what are my options for binding unprivileged daemon to a privileged port? I do know that Linux has privbind project. Is there a solution that can be used together with Mac OS X's launchd? Can/Should I use privbind and hack it together with launchd.plist format?

share|improve this question
up vote 1 down vote accepted

Apache supports several special debugging defines, to be used with -D:

  • NO_DETACH: Don’t detach from the controlling terminal.
  • FOREGROUND: (implies NO_DETACH): Don’t daemonize or detach from the controlling terminal
  • ONE_PROCESS (implies NO_DETACH and FOREGROUND): Don’t allow a child process to handle client requests; use the initial process instead.
  • DEBUG (implies all of the previous): Places the MPM into a special debug mode with additional logging.

Thus, running "httpd -D FOREGROUND" will keep it from daemonizing.

I also ran into a forum thread with a launchd plist for Apache2 that you might be able to adapt.

(Note: I know neither of these answer the actual question, but hopefully they're useful for the problem initially described.)

share|improve this answer
Thanks for your input, although I meant httpd in general sense as "http daemon". It's actually Mongrel2 which I'm spinning my head around .) But your answer does solve the problem for apache. Actually - Mac OS X has this built in and is controlled via "Web sharing" checkbox in sharing pref pane. – Eimantas Jun 2 '11 at 5:44
@Eimantas, I think you can register a listening Socket on port 80 and set the UserName to your unprivileged user; my understanding is that launchd will open that port itself and hand off connections to the daemon, so it doesn't need the privileges to open the port itself. man launchd.plist has a lot of information. – Handyman5 Jun 9 '11 at 0:04

Your Answer


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.