Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Akshada_Systematix

macrumors newbie
Original poster
Mar 22, 2017
1
0
I have created a LaunchDaemon service which runs a application

sudo launchctl load /Library/LaunchDaemons/com.testapp.plist

Here is my com.testapp.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>com.testapp</string>
<key>OnDemand</key>
<false/>
<key>UserName</key>
<string>root</string>
<key>GroupName</key>
<string>wheel</string>
<key>KeepAlive</key>
<true/>
<key>StandardErrorPath</key>
<string>/var/log/OutputLog1.log</string>
<key>StandardOutPath</key>
<string>/var/log/OutputLog2.log</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/TestApplication/Test.app/Contents/MacOS/Test</string>
</array>
</dict>
</plist>

It is working fine. But when I reboot my system, launchdaemon start my application but it kills the application.

Log which I get in console is,

20/03/17 7:15:25.239 PM Test[50]: Untrusted apps are not allowed to connect to Window Server before login.
20/03/17 7:15:25.239 PM Test[50]: Set a breakpoint at CGSLogError to catch errors as they are logged.
20/03/17 7:15:25.239 PM Test[50]: On-demand launch of the Window Server is allowed for root user only.
20/03/17 7:15:25.239 PM Test[50]: CGSLookupServerRootPort: Failed to look up the port for "com.apple.windowserver.active" (1102)
20/03/17 7:15:25.239 PM Test[50]: On-demand launch of the Window Server is allowed for root user only.
20/03/17 7:15:25.239 PM Test[50]: CGSLookupServerRootPort: Failed to look up the port for "com.apple.windowserver.active" (1102)
20/03/17 7:15:25.239 PM Test[50]: This user is not allowed access to the window system right now.
20/03/17 7:15:34.721 PM Test[50]: RegisterApplication(), FAILED TO establish the default connection to the WindowServer, CGSDefaultConnection() is NULL.
20/03/17 7:15:34.732 PM Test[50]: CGSConnectionByID: 0 is not a valid connection ID.
20/03/17 7:15:34.732 PM Test[50]: CGSConnectionByID: 0 is not a valid connection ID.
20/03/17 7:15:34.735 PM Test[50]: CGSConnectionByID: 0 is not a valid connection ID.
20/03/17 7:15:34.735 PM Test[50]: CGSConnectionByID: 0 is not a valid connection ID.
20/03/17 7:15:34.735 PM Test[50]: CGSConnectionByID: 0 is not a valid connection ID.
20/03/17 7:15:34.736 PM Test[50]: CGSConnectionByID: 0 is not a valid connection ID.
20/03/17 7:15:34.736 PM Test[50]: Invalid Connection ID 0
20/03/17 7:15:34.970 PM Test[50]: CGSLookupServerRootPort: Failed to look up the port for "com.apple.windowserver.active" (1102)
20/03/17 7:15:34.970 PM Test[50]: CGSLookupServerRootPort: Failed to look up the port for "com.apple.windowserver.active" (1102)
20/03/17 7:15:34.970 PM Test[50]: CGSLookupServerRootPort: Failed to look up the port for "com.apple.windowserver.active" (1102)
20/03/17 7:15:34.972 PM Test[50]: CGSConnectionByID: 0 is not a valid connection ID.
20/03/17 7:15:34.972 PM Test[50]: CGSConnectionByID: 0 is not a valid connection ID.
20/03/17 7:15:34.972 PM Test[50]: CGSConnectionByID: 0 is not a valid connection ID.
20/03/17 7:15:34.976 PM Test[50]: CGSConnectionByID: 0 is not a valid connection ID.
20/03/17 7:15:34.977 PM Test[50]: CGSConnectionByID: 0 is not a valid connection ID.

I also checked application running state from Activity Monitor which shows that application is running.

Also checked the daemon state by

sudo launchctl list | grep testapp

which also shows that daemon is also running.

I am not able to get the main cause of this issue .

Please help.

Thanks in advance.
 

chown33

Moderator
Staff member
Aug 9, 2009
11,003
8,899
A sea of green
See this related thread:
https://forums.macrumors.com/threads/run-script-with-launchd-at-login.2035212/

There are several errors in what you're doing. The most directly relevant log lines are:
Code:
20/03/17 7:15:25.239 PM Test[50]: Untrusted apps are not allowed to connect to Window Server before login.
20/03/17 7:15:25.239 PM Test[50]: On-demand launch of the Window Server is allowed for root user only.
20/03/17 7:15:25.239 PM Test[50]: This user is not allowed access to the window system right now.
Post #7 in the above thread gives links to important reference docs for making agents and daemons. You'll need to read them carefully and follow all the rules.

Or just use a Login Item, as described here:
https://support.apple.com/kb/PH21985?locale=en_US
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.