如何调试无法在启动时运行的启动脚本?

| 我有一些自制软件的启动脚本。但是,当我重新启动计算机时,必须手动运行它们:
launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.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>KeepAlive</key>
  <true/>
  <key>Label</key>
  <string>com.mysql.mysqld</string>
  <key>Program</key>
  <string>/Users/dash/.local/Cellar/mysql/5.1.49/bin/mysqld_safe</string>
  <key>RunAtLoad</key>
  <true/>
  <key>UserName</key>
  <string>dash</string>
  <key>WorkingDirectory</key>
  <string>/Users/dash/.local/var</string>
</dict>
</plist>
我认为这应该在启动时发生。我想念什么?     
已邀请:
        在您的plist中,发现调试的最佳方法是:
<key>StandardErrorPath</key>
<string>/tmp/mycommand.err</string>
<key>StandardOutPath</key>
<string>/tmp/mycommand.out</string>
打开控制台应用程序,在“所有消息”中,当您的应用程序失败或成功时,您应该会看到条目。像这样:
4/28/15 10:43:19.938 AM com.apple.xpc.launchd[1]: (mycommand[18704]) Service exited with abnormal code: 1
我在ProgramArguments中遇到的问题将命令的每一项作为数组中的
<string>
项。 编辑: 就我而言,为shell脚本生成一个简单的包装效果更好。 该脚本设置了基本的文件夹结构,以将外壳程序脚本制作为OS X \“ app \”-https://gist.github.com/mathiasbynens/674099。这对于您的
mysql -u arg1
命令可能会更好。     
        一种可能性:在目录中查找:
/private/var/db/launchd.db/
并为您的用户优化\“ com.apple.launchd.peruser。### \”文件。打开它,看看是否有类似这样的条目:
<key>com.mysql.mysqld.plist</key>
<dict>
    <key>Disabled</key>
    <true/>
</dict>
如果是这样,请尝试将其设置为
<false/>
。寻找相同内容的另一个文件是:
/private/var/db/launchd.db/com.apple.launchd/overrides.plist
    
        start命令期望作业Label作为其参数,因此您可以使用以下命令启动它:
launchctl start com.myfile.hostname.plist
要停止,只需执行以下操作...
launchctl stop com.myfile.hostname.plist
完成所有测试后,您将注销然后再加载以进行加载,或者如果您的plist文件位于用户的Library文件夹中,请键入以下内容...
launchctl load ~/Library/LaunchAgents/com.myfile.hostname.plist
    
        尝试重命名。将文件名更改为:
~/Library/LaunchAgents/com.mysql.mysqld2.plist
和plist中的Label部分可以:
<key>Label</key>
<string>com.mysql.mysqld2</string>
如果保存备份副本,请确保将其移到〜/ Library / LaunchAgents /目录之外。 最后,无需注销并重新登录,而无需使用launchctl进行加载。这将使launchd单独从您的\“ LaunchAgents \”目录中将其拾取,并从组合中删除另一个变量(即launchctl)。     
        对我来说,到目前为止,其他解决方案也无济于事。我的问题有点难以调试,因为plist文件正确,脚本在终端中单独运行良好。一切看起来都很好,但是不起作用。 我通过执行检查日志文件
tail -f /var/log/system.log
然后通过使用以下命令再次卸载和加载服务:
launchctl unload ~/Library/LaunchAgents/example.plist
launchctl load ~/Library/LaunchAgents/example.plist
我从日志文件中发现了一条错误消息:
Program specified by service is not a Mach-O executable file.
到底是什么意思我没有谷歌。但是,我感觉是因为我没有在shell脚本的开头添加add18ѭ。因为有时我懒于添加这行。 添加标题后,一切正常。     

要回复问题请先登录注册