4

TL;DR:有没有办法在我的机器启动时禁用 Pow 服务器启动,但保留powder up在我需要它运行时手动启动服务器的能力?

我正在使用Pow进行本地开发(并通过Powder gem进行管理)。我想设置 Pow,以便服务器不会在启动时自动启动,因为运行它会耗尽我的电池寿命,而且我并不总是在编码。

Pow 已自行添加launchd,我似乎无法解决 Pow 服务器在启动后未运行的情况,但powder up在我需要启动服务器时仍可以通过其他等效命令运行。

我试过的没有奏效:

  • 为进程设置禁用键cx.pow.powd通过launchctl unload -w ~/Library/LaunchAgents/cx.pow.powd防止 Pow 在启动时启动,但也防止进程在我需要时手动启动
  • 在 cx.pow.powd.plist 文件中设置RunAtLoadNO也不起作用,后来意识到这不是为了控制守护程序的启动行为。
4

3 回答 3

3

忘记发布我最终弄清楚的答案。

事实证明这实际上非常简单,并且在Lunchy(launchctl 的友好包装器)和快速的o' bash 别名的帮助下非常容易。有点hacky,我不太了解launchctl,但这可以解决问题。

步骤(假设已经安装了Lunchy和Pow):

  1. Run lunchy stop -w pow:这将停止 Pow,并在 launchctl 中将服务标记为禁用,因此机器启动时不会加载 Pow。(这与我最初尝试的问题相同。)
  2. .bash_profile在您的(或.profile等)中设置别名以强制启动服务。=>alias pu='lunchy start -F pow'

当你重启你的机器时,应该停止 Pow,然后运行pu(或你的别名)应该启动它。您可以通过运行查看之前/之后运行的服务列表lunchy status

这也是一种 hacky 但有效的方法,可以启动/停止开发所需的服务组,但不一定要在其余时间运行(mongo、redis 等)。

于 2014-10-28T21:58:12.217 回答
0

KeepAlivePathState钥匙 一起使用。

PathState <dictionary of booleans>
       Each key in this dictionary is a file-system path. If the value of the key is true, then the job
       will be kept alive as long as the path exists.  If false, the job will be kept alive in the
       inverse condition. The intent of this feature is that two or more jobs may create semaphores in
       the file-system namespace.

当您要启动 pow 服务器时,在路径上创建一个文件。

于 2014-02-24T12:22:38.960 回答
0

我最近遇到了这个问题并通过简单地移动cx.pow.powd.plist到另一个文件夹来解决它,这成功地禁用了 Pow 服务器的自动启动。当我想再次启动它时,我只需cx.pow.powd.plist返回~/Library/LaunchAgents/cx.pow.powd并运行powder up.

于 2015-09-01T13:44:30.593 回答