Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
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. –  RedGrittyBrick Feb 23 '11 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 '11 at 12:55
    
Do you have a little brother? Little brothers are good for automated tasks :D –  Andrei Duma Feb 23 '11 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 '11 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. –  Raim Feb 26 '11 at 10:58
add comment

1 Answer

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.)

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.