我有一个 launchd 守护进程,~/Library/LaunchAgents它在小牛队中运行良好。但它不会从优胜美地公开测试版开始。守护进程plist是这样的(我的用户名是darksairUID 501)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.darksair.retrmail</string>
<key>ProgramArguments</key>
<array>
<string>/Users/darksair/bin/retrmail.py</string>
</array>
<key>KeepAlive</key>
<false/>
<key>StartInterval</key>
<integer>300</integer>
<key>LaunchOnlyOnce</key>
<false/>
<key>UserName</key>
<string>darksair</string>
<key>ProcessType</key>
<string>Standard</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/Users/darksair/Python/bin:/Users/darksair/Python3/bin:/Users/darksair/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
<key>StandardOutPath</key>
<string>/Users/darksair/logs/retrmail.log</string>
<key>StandardErrorPath</key>
<string>/Users/darksair/logs/retrmail.log</string>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
基本上它应该~/bin/retrmail.py每5分钟运行一次。
我注意到在 Yosemite 中,launchd 升级到 2.0,并且 launchctl 有新的命令。我试过
sudo launchctl kickstart user/501/org.darksair.retrmail
Run Code Online (Sandbox Code Playgroud)
它说
Could not find service "org.darksair.retrmail" in domain for uid: 501
Run Code Online (Sandbox Code Playgroud)
我也试过老派
sudo launchctl load ~/Library/LaunchAgents/retrmail.plist …Run Code Online (Sandbox Code Playgroud) 我使用自制软件安装了 Nginx ,完成安装后显示以下消息:
In the interest of allowing you to run `nginx` without `sudo`, the default
port is set to localhost:8080.
If you want to host pages on your local machine to the public, you should
change that to localhost:80, and run `sudo nginx`. You'll need to turn off
any other web servers running port 80, of course.
You can start nginx automatically on login running as your user with:
mkdir -p ~/Library/LaunchAgents
cp #{prefix}/org.nginx.nginx.plist ~/Library/LaunchAgents/
launchctl load …Run Code Online (Sandbox Code Playgroud) 如何在 Mac OS X 中设置环境变量,以便它们可用于 GUI 应用程序而不使用~/.MacOSX/environment.plist或登录挂钩(因为这些已弃用)?
我尝试使用launchd按时更新Homebrew。我的 plist 文件显示在这里:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>ms.liu.homebrew.update</string>
<key>UserName</key>
<string>LiuMS</string>
<key>ProcessType</key>
<string>Background</string>
<key>EnvironmentVariables</key>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/brew</string>
<string>update</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>20</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
<key>StandardOutPath</key>
<string>/usr/local/logs/ms.liu.homebrew.update.out</string>
<key>StandardErrorPath</key>
<string>/usr/local/logs/ms.liu.homebrew.update.err</string>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
它确实以某种方式工作:我可以launchctl start ms.liu.homebrew.update手动执行以更新我的 Homebrew。但是,launchd 不会定期执行此服务:对 stdout 重定向到的文件的最后更改是两天前。
我试图获取有关此服务的信息,但一无所获:
> launchctl print user/%MyPID%/ms.liu.homebrew.update``
Could not find service "ms.liu.homebrew.update" in domain for uid: %MyPID%
Run Code Online (Sandbox Code Playgroud)
看起来我还没有成功加载我的服务。如何?我使用过,launchctl load但似乎已被弃用。手册页推荐引导程序:
> launchctl bootstrap user/%MyPID% %Path-to-plist%
> %Path-to-plist%: Service cannot load in …Run Code Online (Sandbox Code Playgroud) 我有一个709最大用户进程。我想加倍,或更多。
第一:ulimit
> ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 256
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 709
virtual memory (kbytes, -v) unlimited
Run Code Online (Sandbox Code Playgroud)
好吧 :
> sudo ulimit -u 1418
Password:
Run Code Online (Sandbox Code Playgroud)
让我检查...
> ulimit -a
core file …Run Code Online (Sandbox Code Playgroud) 为什么我的配置 plist 文件没有使用 launchctl 作为服务加载?
我正在运行 OSX Yosemite,我已经阅读了这个关于使用 launchctl http://nathangrigg.net/2012/07/schedule-jobs-using-launchd/ 的优秀教程
我已经使用服务的配置创建了一个正确的 .plist 文件(我知道这是正确的,因为它几乎是我几年前创建的工作 plist 配置文件的副本)。我输入
launchctl load ~/Library/LaunchAgents/com.apple.myservice.plist
Run Code Online (Sandbox Code Playgroud)
并得到回应
~/Library/LaunchAgents/com.apple.myservice.plist: File exists
Run Code Online (Sandbox Code Playgroud)
这不是非常具有描述性,但我去打字
launchctl start com.apple.myservice
Run Code Online (Sandbox Code Playgroud)
并且没有输出,什么也没有发生。我也尝试使用
launchctl enable ~/Library/LaunchAgents/com.apple.myservice.plist
Run Code Online (Sandbox Code Playgroud)
我只是得到一个
Usage: launchctl enable <service-target>
Run Code Online (Sandbox Code Playgroud)
作为回应。
有人可以回复在 OSX Yosemite 上加载启动服务的正确语法吗?
我使用Apple 看似简单的文档创建了一个 LaunchDaemon 来运行我编写的 Node.js 脚本。
这是plist文件。它基本上是 Apple 文档中的复制粘贴,设置为每 300 秒运行一次:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.wintr.eodemail</string>
<key>ProgramArguments</key>
<array>
<string>~/projects/eod_email/eod</string>
</array>
<key>StartInterval</key>
<integer>300</integer>
<key>StandardOutPath</key>
<string>/var/log/eod-email.log</string>
<key>StandardErrorPath</key>
<string>/var/log/eod-email.log</string>
<key>Debug</key>
<true/>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
这是我遇到的错误/var/log/system.log:
Jul 22 10:55:52 Nick-Cox com.apple.xpc.launchd[1] (com.wintr.eodemail[7097]): Service could not initialize: 14E46: xpcproxy + 13421 [1402][7D917364-B96E-3F93-B923-A89B5BF5736D]: 0x2
Run Code Online (Sandbox Code Playgroud)
我所做的:
我听说
sudo launchctl limit maxfiles 64000 unlimited
Run Code Online (Sandbox Code Playgroud)
和
conf=/etc/sysctl.conf
if sudo cat $conf | command rg kern.maxfiles ; then
ecerr "kern.maxfiles is already set in $conf"
else
sudo echo 'kern.maxfiles=40480
kern.maxfilesperproc=28000' >> "$conf"
fi
Run Code Online (Sandbox Code Playgroud)
对于以前版本的 macOS,但这些都不适用于 Big Sur。
我正在尝试制作一个 plist 文件,以便在启动时启动 nginx。使用launchctl它启动nginx 时会启动服务。但它无法卸载它,并打印“找不到指定的服务”。
$ ps aux | grep nginx
me (...) grep nginx
$ sudo launchctl load /System/Library/LaunchDaemons/nginx.plist
(no output)
$ ps aux | grep nginx
me (...) grep nginx
nobody (...) nginx: worker process
root (...) nginx: master process /opt/nginx/sbin/nginx
$ sudo launchctl unload /System/Library/LaunchDaemons/nginx.plist
/System/Library/LaunchDaemons/nginx.plist: Could not find specified service
Run Code Online (Sandbox Code Playgroud)
这是/System/Library/LaunchDaemons/nginx.plist的内容
$ cat /System/Library/LaunchDaemons/nginx.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key><string>nginx</string>
<key>Program</key><string>/opt/nginx/sbin/nginx</string>
<key>KeepAlive</key><true/>
<key>NetworkState</key><true/>
<key>StandardErrorPath</key><string>/opt/nginx/logs/system.log</string>
<key>LaunchOnlyOnce</key><true/>
</dict> …Run Code Online (Sandbox Code Playgroud) 我在 launchctl 中设置了几个服务,它们都在启动时启动,并在出于任何原因停止时自动重新启动。到目前为止,这很棒。
但有时我希望其中一项服务退出而不是重新启动一段时间。
除了从launchctl中删除服务(这也会立即停止它,我不想这样做)之外,是否有推荐的方法来做到这一点?
我一直在尝试提高优胜美地的 maxfile 限制和 maxfileperproc 限制,但没有运气。我在 etc 文件夹中创建了一个 sysctl.conf 文件,它在通过 grep 显示时成功增加了值。
但是,如果我查看launchctl limit maxfiles,该值仍然不正确。
一些解决方案似乎使用 ulimit -n 来设置限制,但是在终端中时,我实际上无法使用它。它给了我“无效参数”或“未经授权的操作”的错误。我已经通过 bash_profile 脚本成功增加了 ulimit,但是由于应用程序是从应用程序运行的,而不是从 shell 运行的,所以它无关紧要。我还通过 root 用户成功地增加了 ulimit,但是当它被注销时,它不会保存更改。
理想情况下,我正在寻找像 launchd.conf 文件那样工作的东西,并且只是在重新启动时自动增加 launchctl limit maxfiles {#}。
有没有办法成功地做到这一点?也许使用像 Lingon 这样的 3rd 方,或者使用启动守护程序?
谢谢!
我已经阅读了 plist 和 launchd.plist 的手册页,以及有关使用 plist 文件在登录时运行脚本的帖子;但我似乎可以让事情运转起来。
我的脚本位置和权限:
sshfs_mounts.sh:
ls -al Library/scripts/
-rwxr-xr-x 1 jason staff 288 May 10 17:06 sshfs_mounts.sh
Run Code Online (Sandbox Code Playgroud)
cat Library/scripts/sshfs_mounts.sh
#!/bin/bash
#
## automounting of sshfs directories
mount_cosmic ()
{
/usr/local/bin/sshfs jason@iss.nasa.gov:/media/NetworkShare/spacedock-1 /Users/jason/share;
}
mount |grep "/Users/jason/share/"
if [ $? == 1 ] && [ -d "/Users/jason/share" ] && [ $USER == "jason" ]; then
mount_cosmic
fi
Run Code Online (Sandbox Code Playgroud)
从原始帖子编辑:
如果我手动运行脚本,它会按预期执行。我可以加载 plist ( launchctl load ~/Library/LaunchAgents/local.sshfs.plist) 并启动它 ( launchctl start ~/Library/LaunchAgents/local.sshfs),但它不运行脚本。在日志 ( cat /var/log/system.log |grep local.sshfs …
我正在尝试在 OS X Lion Server 上设置YouTrack并使用launchd. 我已经下载了 YouTrack jar 文件,我可以使用java -Xmx512m -jar youtrack.jar 8080. 我还将上述运行命令包装在一个类似于此的 shell 脚本中,这基本上让我可以使用youtrack start和与活动实例进行交互youtrack stop。它将进程的进程 id 存储java在一个文件中并退出,以便能够停止正在运行的实例,只允许一个实例等。
为了在启动时运行这个命令,我创建了一个简单的 launchd plist 并将它放在 /Library/LaunchDaemons 中,按照man launchd.plist. 使用的主要键是ProgramArguments( youtrack start) 和RunAtLoad(true)。问题是,当运行表单时,命令行将youtrack start创建一个包含java进程pid 的文件,我可以在top或 中看到这个进程ps ax。但是当命令由 lanuchd ( sudo launchctl load /Library/LaunchDaemons/org.example.youtrack.plist)运行时,生成的 pid 将与任何正在运行的进程的 pid 不匹配,并且 YouTrack Web …
launchctl ×13
macos ×10
launchd ×8
mac ×3
ulimit ×3
daemon ×2
osx-yosemite ×2
process ×2
boot ×1
homebrew ×1
kernel ×1
macos-bigsur ×1
nginx ×1
permissions ×1
plist ×1