如何从命令行启动/停止/重新启动launchd服务?

如何重新启动,比如说我的httpd或afpd,运行任何Mac OS X> = 10.5(Leopard-),而不必使用GUI并转到系统偏好设置 – >共享并取消选中/检查“Web共享”?

我正在寻找相当于Debian的invoke-rc.d apache2 restart的规范。

编辑:这个问题是关于启动受控服务的一般 ,不是特别是Apache(这只是一个例子)。

嗨launchctl(8)是你的朋友。 请记住,某些服务(例如sshd)在configuration文件中被禁用,因此在加载时需要使用'-w'开关。 这是一个sshd的例子:

  $sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist 

您可以使用“卸载”子命令停止服务。

  $sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist 

要列出这些服务,正如你可能已经猜到的那样,使用'list'子命令;)

玩得开心

sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

您正在寻找launchctl

 SYNOPSIS launchctl [subcommand [arguments ...]] DESCRIPTION launchctl interfaces with launchd to load, unload daemons/agents and gen- erally control launchd. launchctl supports taking subcommands on the command line, interactively or even redirected from standard input. These commands can be stored in $HOME/.launchd.conf or /etc/launchd.conf to be read at the time launchd starts. 
 sudo apachectl restart 

与其他操作系统一起工作,它也是Apache的一部分。

这个名为Lingon的是一个小而有用的应用程序。 Lingon免费版本在这里有时重新启动服务可能会非常棘手。

 syslog -w 

阅读帮助虽然。

你可以简单地做

 sudo launchctl stop com.openssh.sshd 

而且你不需要卸载和加载服务。

我不知道这是你在找什么,但你可以尝试一个简单的命令,我觉得相当有用。