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?
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.)
apache
and 2.x asapache2
.