How do I restart, say for example my httpd or afpd, running any Mac OS X >= 10.5 (Leopard-), without having to use the GUI and go to System Preferences -> Sharing and unchecking/checking "Web Sharing"?
I'm looking for the canonical equivalent to Debian's invoke-rc.d apache2 restart
.
EDIT: The question is about launchd controlled services in general, not specifically Apache (-which was simply an example).
launchctl(8) is your friend. Just keep in mind that some of the services (sshd for example) are disabled in the configuration file so you will need to use the
-w
switch when loading them. Here is a sshd example:You can stop the service using the
unload
subcommand.To list the services, as you might have already guessed use the 'list' subcommand ;)
To restart a service, you can use the
launchctl kickstart
command, together with the-k
option. For example, to restart apache, you can useThis information is from the
launchctl
manual page:You could simply do
If you don't known the full service name, you can do
If you still don't find the service you expected, try to run without the root identity:
And you don't need to unload and load service.
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
You are looking for
launchctl
.Just in case if you are looking for
launchctl reload
, you can define shell function in your~/.bashrc/.zshrc
as I did:Command execution looks like ->
lctl reload <your-plist-name>.plist
Works with other OSses as well as it is part of Apache.
For restarting, I think the easiest way is to kill the process. Assume you have configured keepalive, which most daemon processes do.
pkill apache2
will do. Then the process will start again by itself.There is a small & useful app for this named Lingon. Lingon freeware edition is here sometimes restarting a service can be tricky.
reading helps though.