1

I've installed Apache using MacPorts. It crashes every once in a while, and I need to manually restart it.

Is there a way to get Apache to automatically restart if it dies for some reason? Perhaps using launchd somehow?

5
  • 1
    Have you considered posting a question about stopping Apache from crashing? It really shouldn't ever crash. Perhaps there are some configuration details some log entries or some known circumstances that you could describe. Feb 23, 2011 at 9:44
  • I second that idea, maybe you want to fix the issue that causes Apache to crash or be more specific about any error logs.
    – slhck
    Feb 23, 2011 at 12:55
  • Do you have a little brother? Little brothers are good for automated tasks :D Feb 23, 2011 at 20:24
  • The current Macports version is apparently 1.3.41, the current version is 2.2.17, Snow's Apache is 2.2.15
    – tobylane
    Feb 23, 2011 at 21:15
  • @tobylane There are two branches of the Apache web server which have been developed in parallel for years. MacPorts offers both 1.x as apache and 2.x as apache2.
    – raimue
    Feb 26, 2011 at 10:58

1 Answer 1

1

Use launchd to start Apache, and make Apache run in the foreground so launchd can monitor it and restart it if it crashes. Since the system includes a launchd item (/System/Library/LaunchDaemons/org.apache.httpd.plist) to start the built-in version of Apache, I'd just copy that to /Library/LaunchDaemons, change the filename and Label so launchd won't get them confused, remove the Disabled key, and change ProgramArguments to point to the MacPorts version of Apache. Be sure to keep the -D and FOREGROUND arguments to httpd, or it'll daemonize itself and launchd will start another instance and nothing useful will get done.

(And do follow @RedGrittyBrick's advice about finding the actual cause of the crash. While launchd is the "right" way to start a daemon like Apache on Mac OS X, it's just a band-aid for whatever problem Apache is having.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .