4

I've been building a golang app with system tray GUI. I wanted launchctl to run my program whenever I log in. Program compiles and runs without any error, however, when launchctl runs it, I see this: Service exited with abnormal code: 78. Perhaps it has something to do with rights.

  • First I tried to set rights of a current user to both plist file and the binary. Still error 78.

  • Then I changed the rights of plist file and the binary to root and run sudo launchctl. I still see error 78.

/var/log/system.log has this errors:

14:46:00 Macchiato com.apple.xpc.launchd[1] (com.test.test[519]): Service could not initialize: 18A391: xpcproxy + 11291 [1534][8188841E-6D08-3F80-8488-9B5D7462BACB]: 0xd
14:46:00 Macchiato com.apple.xpc.launchd[1] (com.test.test[519]): Service exited with abnormal code: 78
14:46:00 Macchiato com.apple.xpc.launchd[1] (com.test.test): Service only ran for 0 seconds. Pushing respawn out by 10 seconds.

The plist file itself is:

<?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.test.test</string>
        <key>ProgramArguments</key>
        <array>
                <string>/Users/test-user/test/test</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>ProcessType</key>
        <string>Standard</string>
        <key>KeepAlive</key>
        <true/>
        <key>StandardErrorPath</key>
        <string>/var/log/test-err.log</string>
        <key>StandardOutPath</key>
        <string>/var/log/test-out.log</string>
</dict>
</plist>

Error logs are empty.

When I run the binary manually, the icon of the app appears on the system tray, as expected.

There's one interesting moment – if I manually type launchctl load -w com.test.test.plist, app runs nicely – until the reboot. After I reboot, launchctl throws 78 error.

Why is this happening?

krlc
  • 376
  • 4
  • 9

2 Answers2

2

I think I solved my own question. It seems the error 78 comes when I use

<key>StandardErrorPath</key>
<string>/var/log/test-err.log</string>
<key>StandardOutPath</key>
<string>/var/log/test-out.log</string>

When I removed this lines, the error disappeared. This is especially odd, because the plist file has root permissions and launchd runs as root either...

krlc
  • 376
  • 4
  • 9
  • 2
    I think you're confused about the distinction between launch agents (which run as regular users inside user sessions) and launch daemons (which mostly run as root, independent of who's logged in). If you want this to run in a user session, it *must* be an agent, in which case it will not have permissions to write to /var/log. – Gordon Davisson Feb 04 '19 at 00:33
  • When you remove the paths above, does the log and error output end up elsewhere or nowhere? – John Dough Dec 14 '19 at 05:17
  • This has no effect for me. Notably I'm also using a go program and built in functions (sleep) work. – Paul Jun 19 '21 at 19:09
1

Error 78 means that there is no permission to write to the log files you have specified.

to resolve this error, change the owner or the permissions of the log files.

Phil Y
  • 186
  • 1
  • 4