services
era un comando "nascosto" in Homebrew. Ce n'erano un gruppo che non erano presenti nell'output brew help
. Ha, come i comandi non documentati sono soliti fare, andato via nel deposito ufficiale ed è diventato un " comando esterno "mantenuto in un altro repository aggiuntivo (in questo caso un istanza in quanto è così semplice).
Puoi installarlo nella configurazione Homebrew eseguendo:
> curl -o /usr/local/bin/brew-services.rb https://gist.githubusercontent.com/lwe/766293/raw/75a7907004bbff0eb3b072d1d951be2cfe7e5020/brew-services.rb
> chmod +x /usr/local/bin/brew-services.rb
> brew services help
usage: [sudo] brew services [--help] <command> [<formula>]
Small wrapper around 'launchctl' for supported formulas, commands available:
cleanup Get rid of stale services and unused plists
list List all services managed by 'brew services'
restart Gracefully restart selected service
start Start selected service
stop Stop selected service
Options, sudo and paths:
sudo When run as root, operates on /Library/LaunchDaemons (run at boot!)
Run at boot: /Library/LaunchDaemons
Run at login: /Users/ian/Library/LaunchAgents
In alternativa puoi saltare services
e solo creare un file plist per questo. Ad esempio, crea ~/Library/LaunchAgents/org.mongodb.mongod.plist
con:
<?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>org.mongodb.mongod</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/Cellar/mongodb/2.6.4/bin/mongod</string>
<string>run</string>
<string>--config</string>
<string>/usr/local/Cellar/mongodb/2.6.4/mongod.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>UserName</key>
<string>{your_username}</string>
<key>WorkingDirectory</key>
<string>/usr/local</string>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/mongodb/output.log</string>
<key>StandardOutPath</key>
<string>/usr/local/var/log/mongodb/output.log</string>
</dict>
</plist>
Cambia semplicemente {your_username}
nel tuo vero nome utente, quindi esegui:
launchctl load ~/Library/LaunchAgents/org.mongodb.mongod.plist
per registrare i plist con launchd. Ora puoi avviare e fermare MongoDB con:
launchctl start org.mongodb.mongod
launchctl stop org.mongodb.mongod
Nota, la soluzione plist precedente è stata presa da questa eccellente risposta di Overflow dello stack .