Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I debug a Launchd script that doesn't run on startup?

Tags:

macos

launchd

I have some Launchd scripts from homebrew. However I have to manually run them when I restart my computer:

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> 

I thought this should happen on startup. What am I missing?

like image 253
dd. Avatar asked Jun 13 '11 23:06

dd.


2 Answers

Best way I found to debug, in your plist:

<key>StandardErrorPath</key> <string>/tmp/mycommand.err</string> <key>StandardOutPath</key> <string>/tmp/mycommand.out</string> 

Open Console app, in "All Messages" you should see entries when your app fails or succeeds. Like this:

4/28/15 10:43:19.938 AM com.apple.xpc.launchd[1]: (mycommand[18704]) Service exited with abnormal code: 1 

The issue I had was with ProgramArguments takes each item of command as <string> item in the array.

EDIT: In my case, generating a simple wrapper for shell script worked even better. This script sets up basic folder structure to make a shell script into an OS X "app" - https://gist.github.com/mathiasbynens/674099. This might work better for your mysql -u arg1 command.

like image 107
bgs Avatar answered Sep 19 '22 12:09

bgs


For me, other solutions so far do not help me. My problem is kinda hard to debug, because the plist file is correct, the script is running fine alone in a terminal. Everything looks fine, but doesn't work.

I checked the log file by executing

tail -f /var/log/system.log 

And then by unloading and loading the service again with the commands:

launchctl unload ~/Library/LaunchAgents/example.plist launchctl load ~/Library/LaunchAgents/example.plist 

I found an error message from the log file:

Program specified by service is not a Mach-O executable file. 

What does it really mean? I didn't google. But, I feel it's because I didn't add #!/bin/bash at the beginning of the shell script. Because I am lazy to add this line sometimes.

After adding the heading, everything works fine.

like image 42
sgon00 Avatar answered Sep 20 '22 12:09

sgon00