2017-03-22 3 views
1

Ich habe einen LaunchDaemon-Dienst erstellt, die eine Anwendung läuftAnwendung nicht starten auf Systemneustart

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

Hier ist meine 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> 

Es funktioniert gut. Aber wenn ich mein System neu starte, startet launchdaemon meine Anwendung, aber es bringt die Anwendung zum Absturz.

Log, die ich in der Konsole erhalten ist,

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. 

Ich habe auch Anwendungszustand von Activity Monitor ausgeführt wird, die zeigt, dass die Anwendung ausgeführt wird.

überprüft auch den Daemon Zustand von

sudo launchctl list | grep testapp 

, die auch zeigt, dass Daemon auch ausgeführt wird.

Auch unter meinem stdout log von Daemon plist ist (Es protokolliert das Protokoll, das ich in meiner Anwendung tat):

2017-03-27 18:04:34.841 Test[802:16596] Application Started... 
2017-03-27 18:04:34.896 Test[802:16596] argc : 1 
2017-03-27 18:04:35.123 Test[802:16596] applicationWillFinishLaunching... 
2017-03-27 18:04:35.145 Test[802:16596] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data 
2017-03-27 18:04:35.146 Test[802:16596] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data 
2017-03-27 18:04:35.147 Test[802:16596] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data 
2017-03-27 18:04:35.148 Test[802:16596] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data 
2017-03-27 18:04:35.224 Test[802:16596] applicationDidFinishLaunching... 
2017-03-27 18:04:35.238 Test[802:16596] applicationDidChangeOcclusionState... 
2017-03-27 18:04:35.253 Test[802:16596] applicationDidChangeOcclusionState... 
2017-03-27 18:05:13.000 Test[820:17234] Application Started... 
2017-03-27 18:05:13.072 Test[820:17234] argc : 1 
2017-03-27 18:06:09.566 Test[92:505] Application Started... 
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL. 
2017-03-27 18:06:17.845 Test[92:505] argc : 1 
2017-03-27 18:06:18.254 Test[92:505] applicationWillFinishLaunching... 
2017-03-27 18:06:18.299 Test[92:505] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data 
2017-03-27 18:06:18.300 Test[92:505] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data 
2017-03-27 18:06:18.300 Test[92:505] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data 
2017-03-27 18:06:18.302 Test[92:505] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data 
2017-03-27 18:06:22.918 Test[92:505] In -[NSApplication(NSQuietSafeQuit) _updateCanQuitQuietlyAndSafely], _LSSetApplicationInformationItem(NSCanQuitQuietlyAndSafely) returned error -600 

Ich bin nicht in der Lage, die Hauptursache für dieses Problem zu erhalten.

Bitte helfen.

Vielen Dank im Voraus.

Antwort

1

Wie this answer zeigt, ist die Fehlermeldung:

Untrusted Apps sind nicht auf Windows Server vor der Anmeldung verbinden erlaubt.

irreführend ist, dass es das Problem eines von Vertrauen, wenn sie in Wirklichkeit deutet darauf hin, das Problem ist, dass SieGUI Operationen aus dem falschen Kontext sind versucht.

Starten Daemons Lauf in einem Systemkontext unabhängig und möglicherweise vor jedem Benutzer anmeldet, und haben keinen Zugriff auf den Windows Server - sie nicht eine Benutzeroberfläche präsentieren können.

Kurz gesagt: Wenn Ihre Anwendung eine Benutzeroberfläche darstellt, kann sie nicht als Daemon ausgeführt werden.

dagegen starten Agenten (geladen von /Library/LaunchAgents und ~/Library/LaunchAgents) sind in der Lage eine GUI zu präsentieren, Apple recommends against it.

Vielleicht ist alles, was Sie brauchen, um eine Login-Artikel zu erstellen, obwohl Sie das auf einer Benutzerbasis erstellen müssen.

Einen Überblick über die verschiedenen Möglichkeiten zum Ausführen einer Anwendung, wenn sich ein Benutzer anmeldet, finden Sie unter this answer von mir.

+0

Danke und Entschuldigung aber können Sie bitte das gleiche ausarbeiten? Außerdem aktualisiere ich meine Frage mit dem Log von stdout von daemon plist. –

+0

@ Akshada-Systematix: Sehen Sie, ob mein Update hilft. Was macht deine App? Muss es als root ausgeführt werden? Muss es für jeden Benutzer des Systems ausgeführt werden? Die beste Methode zum Starten Ihrer App hängt von den Antworten auf diese Fragen ab. – mklement0

+0

Der Zweck meiner App ist es, Track-Ort im Hintergrund zu betreiben und es sollte unabhängig von jedem Benutzer, der mich zu Launchdaemon führt. Die App wird ausgeblendet und ist für den Benutzer nicht sichtbar. Dazu habe ich "Window" und "Main Menu" aus dem "MainMenu.xib" meiner Applikation gelöscht. Auch unterhalb der Zeilen hinzugefügt, um meine Anwendung zu verbergen. ProcessSerialNumber psn = {0, kCurrentProcess}; TransformProcessType (& psn, kProcessTransformToBackgroundApplication); Zum Ausblenden habe ich auch versucht, LSUIElement Bitte helfen. –

Verwandte Themen