SSH पर launchctl bootstrap gui/501: headless Mac पर "Could not find domain for" और एरर 125
gui/UID launchd domain तभी बनता है जब कोई Mac के GUI पर login करे, इसलिए SSH से वहाँ agent bootstrap करना फेल होता है। एक बार login करें (या automatic login चालू करें) और GUI Terminal से इंस्टॉल करें, या सर्विस को UserName वाले LaunchDaemon के रूप में चलाएँ।

gui/<uid> launchd domain user-login domain है, और यह तभी बनता है जब वह user Mac की graphical login window पर login करता है। जिस Mac पर किसी ने login नहीं किया, वहाँ SSH से bootstrap करने के लिए कुछ होता ही नहीं, इसलिए launchctl "Could not find domain for" या एरर 125 के साथ फेल हो जाता है। या तो GUI session बनाएँ (Screen Sharing से एक बार login करें, वहीं के Terminal से इंस्टॉल करें, और automatic login चालू करें), या जिन सर्विस को GUI नहीं चाहिए, उनके plist को /Library/LaunchDaemons में UserName key के साथ LaunchDaemon के रूप में इंस्टॉल करें और system domain में bootstrap करें।
कौन-से एरर इसी समस्या की ओर इशारा करते हैं
टूल और आपके चुने domain के हिसाब से इनमें से कोई एक दिखेगा:
"launchctl" failed: Could not find domain for
Could not enable service: 125: Domain does not support specified action
Service cannot load in requested session
Bootstrap failed: 134: Unknown error: 134
Load failed: 5: Input/output error
पहला एरर GitLab के macOS runner दस्तावेज़ में उस एरर के रूप में दर्ज है जो runner को स्थानीय GUI terminal की जगह SSH से मैनेज करने पर मिलता है। दूसरा brew services start syncthing से आया, जिसने macOS 14.6.1 पर /bin/launchctl enable gui/503/homebrew.mxcl.syncthing चलाया था; यह Syncthing फ़ोरम पर रिपोर्ट हुआ। 134 वाली जोड़ी gitlab-runner issue 29324 में तब आई जब रिपोर्ट करने वाले ने headless EC2 Mac पर user/501 आज़माया, और आख़िरी लाइन उसी रिपोर्ट में deprecated launchctl load से आई।
SSH पर gui/<uid> क्यों मौजूद नहीं होता
launchctl(1) man page तीन per-user targets परिभाषित करता है:
login/<asid>: user-login domain, जो "user के GUI पर login करने पर बनता है"।gui/<uid>: login specifier का ही दूसरा रूप, जिसमें audit session की जगह user से पता दिया जाता है।user/<uid>: user domain, जो "logged-in user के बिना भी मौजूद हो सकता है"।
SSH login से GUI login नहीं बनता, इसलिए gui/501 बस मौजूद नहीं होता। Man page कोड 125 की व्याख्या नहीं करता; संदेश सिर्फ़ इतना कहता है: "Domain does not support specified action"। Syncthing की रिपोर्ट में वही user जब GUI पर login हुआ, तो सर्विस शुरू हो गई।
user/<uid> पर जाने से आमतौर पर अलग तरह से फेल होता है। LaunchAgents session types से बँधे होते हैं। TN2083 (archived, Mac OS X 10.5 के लिए लिखा गया) कहता है कि अगर plist में LimitLoadToSessionType सेट नहीं है, तो launchd मान लेता है कि वह Aqua है, यानी GUI login session। यह "Service cannot load in requested session" एरर से मेल खाता है, लेकिन Apple 134 एरर का कारण दस्तावेज़ में नहीं बताता।
कैसे जाँचें कि आप किस context में हैं
launchctl managername
launchctl print gui/$(id -u)
launchctl print user/$(id -u)
launchctl error 125
managername आपके मौजूदा context के job manager का नाम प्रिंट करता है; man page इसे LimitLoadToSessionType में इस्तेमाल होने वाले session types से जोड़ता है। इसे एक बार SSH पर और एक बार GUI login के भीतर Terminal में चलाकर तुलना करें। अगर print gui/$(id -u) फेल हो और print user/$(id -u) चले, तो user का GUI login नहीं है। Man page चेतावनी देता है कि print का आउटपुट API नहीं है, इसलिए scripts में उसे parse न करें।
उपाय 1: वह GUI session बनाएँ जिसकी agent अपेक्षा करता है
यह उन agents के लिए है जिन्हें window server या login session चाहिए। GitLab Runner ऐसा ही एक है: उसके दस्तावेज़ कहते हैं कि runner user-mode LaunchAgent के रूप में चलता है, "The LaunchAgent requires a graphical login session to bootstrap", और उसे LaunchDaemon के रूप में चलाना समर्थित नहीं है।
- Screen Sharing या किसी दूसरे VNC क्लाइंट से कनेक्ट करें और उस अकाउंट से login करें जो सर्विस चलाएगा। Cloud Mac पर पासवर्ड सेट करने और Screen Sharing चालू करने के लिए provider के निर्देश देखें।
- उसी GUI session में Terminal खोलें और installer वहीं चलाएँ, उदाहरण के लिए:
अपने plist के लिए उसी Terminal से bootstrap करें:gitlab-runner install gitlab-runner startlaunchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/<label>.plist - Automatic login चालू करें ताकि reboot के बाद session लौट आए: macOS Ventura 13 या बाद के संस्करण में System Settings > Users & Groups > "Automatically log in as"। Apple बताता है कि FileVault चालू होने पर manual login ज़रूरी है, इसलिए FileVault से एन्क्रिप्टेड Mac पर automatic login उपलब्ध नहीं होता।
Automatic login का मतलब है कि जो भी मशीन restart कर सकता है, उसे उस user का session मिल जाता है। इसे अपनी physical और network exposure के सामने तौलें।
उपाय 2: UserName के साथ LaunchDaemon के रूप में चलाएँ
यह उन सर्विस के लिए है जिन्हें सिर्फ़ फ़ाइलें और नेटवर्क चाहिए, जैसे sync daemon। launchd.plist(5) man page के अनुसार UserName और GroupName सिर्फ़ privileged system domain में लोड होने वाली सर्विस के लिए माने जाते हैं, और LimitLoadToSessionType सिर्फ़ agents पर लागू होता है, क्योंकि system context में अलग-अलग sessions नहीं होते।
- Agent plist को
/Library/LaunchDaemons/<label>.plistमें कॉपी करें और जिस अकाउंट से चलाना है, उसे जोड़ें:<key>UserName</key> <string>ec2-user</string> - अगर
LimitLoadToSessionTypeमौजूद है तो उसे हटा दें।StandardOutPathऔरStandardErrorPathको ऐसी डायरेक्टरी पर सेट करें जो मौजूद हो और जिसमें user लिख सके; issue रिपोर्ट करने वाले को एक default log path बदलना पड़ा था जो मौजूद ही नहीं था। - Ownership और permissions ठीक करें। launchctl(1) की शर्त है कि LaunchDaemons का मालिक root हो और configuration फ़ाइलों पर group और world की write permission न हो:
Issue रिपोर्ट करने वाले को boot पर job शुरू करने के लिए 600 चाहिए था; launchctl(1) खुद सिर्फ़ इतना माँगता है कि फ़ाइल group या others के लिए writable न हो, जो 644 पूरा करता है। अगर 644 के साथ daemon boot पर शुरू न हो, तो 600 आज़माएँ।sudo chown root:wheel /Library/LaunchDaemons/<label>.plist sudo chmod 644 /Library/LaunchDaemons/<label>.plist - इसे system domain में enable और load करें:
sudo launchctl enable system/<label> sudo launchctl bootstrap system /Library/LaunchDaemons/<label>.plist
LaunchDaemon में आप क्या खोते हैं
- GUI नहीं। TN2083 कहता है कि daemon को window server से कनेक्ट करने की अनुमति नहीं है और उसे सिर्फ़ global namespace की सेवाएँ इस्तेमाल करनी चाहिए। जिन jobs को GUI session चाहिए, वे उपाय 1 में आती हैं।
- Privacy prompts नहीं। Syncthing के maintainer बताते हैं कि daemon permission dialogs नहीं दिखा सकता, इसलिए prompt की उम्मीद करने की बजाय binary को पहले से Full Disk Access दें।
- Keychain। Issue 29324 में daemon को login keychain उपलब्ध नहीं था; रिपोर्ट करने वाले ने
SessionCreateजोड़ा और job के भीतर एक समर्पित keychain बनाया। - Vendor का समर्थन। GitLab runner को सिर्फ़ LaunchAgent के रूप में दस्तावेज़ित करता है। Issue 29324 का daemon सेटअप user का workaround है, और रिपोर्ट करने वाला यह भी बताता है कि launchd SIGTERM भेजता है जबकि runner graceful stop के लिए SIGQUIT की अपेक्षा करता है।
कैसे पुष्टि करें कि यह काम कर गया
sudo launchctl print system/<label>
launchctl print gui/$(id -u)/<label>
पहली कमांड daemon के लिए इस्तेमाल करें और दूसरी, GUI session से, agent के लिए। State, PID और last exit status जाँचें। फिर reboot करें और किसी के login करने से पहले दोबारा जाँचें; FileVault के बिना Mac पर daemon चल रहा होना चाहिए, और agent सिर्फ़ automatic login के बाद।
अगर FileVault चालू है, तो fdesetup(8) man page के अनुसार boot के बाद data volume तब तक locked रहता है जब तक कोई अकाउंट पासवर्ड से authenticate न करे, इसलिए /Library/LaunchDaemons में कुछ भी तब तक नहीं चलता जब तक कोई अकाउंट अपने पासवर्ड से data volume unlock न करे। Headless Mac पर यह login window पर remote console से किया जा सकता है, या SSH से: man page Remote Login चालू होने पर SSH से remote unlock का वर्णन करता है, और Apple की platform security guide के अनुसार यह Apple silicon वाले Mac पर macOS 26 या बाद के संस्करण में काम करता है। Restart से पहले Remote Login चालू करें, फिर SSH से अकाउंट के पासवर्ड के साथ कनेक्ट करें; पहला कनेक्शन सिर्फ़ डिस्क unlock करता है और फिर कट जाता है, इसलिए दोबारा कनेक्ट करें। Planned restart के लिए sudo fdesetup authrestart शुरुआती unlock को एक बार के लिए बायपास करता है; man page चेतावनी देता है कि यह हर सिस्टम पर काम नहीं कर सकता।
अगली बार इससे कैसे बचें
- Install scripts में
launchctl loadका इस्तेमाल न करें: launchctl(1) के अनुसारloadऔरunloadusage errors को छोड़कर शून्य लौटाते हैं, जिससे failures छिप जाते हैं।bootstrapऔरbootoutका इस्तेमाल करें और exit status जाँचें। - Provisioning से पहले हर सर्विस के लिए तय करें कि उसे GUI login चाहिए या नहीं, और plist की जगह से यह चुनाव साफ़ रखें: agents के लिए
~/Library/LaunchAgentsया/Library/LaunchAgents, daemons के लिए/Library/LaunchDaemons। - SSH पर चलने वाली provisioning scripts में पहले
launchctl print gui/$(id -u)जाँचें और स्पष्ट संदेश के साथ रुक जाएँ, बजाय इसके कि installer 125 के साथ फेल हो।
स्रोत
- Apple (man page mirror): launchctl(1)
- Apple (man page mirror): launchd.plist(5)
- Apple Developer: Technical Note TN2083: Daemons and Agents
- GitLab Docs: Install GitLab Runner on macOS
- GitLab: gitlab-runner issue 29324
- Syncthing Forum: macOS: can't start syncthing service via Homebrew (125: Domain does not support specified action)
- Apple Support: Set your Mac to automatically log in during startup
- Apple (man page mirror): fdesetup(8)


