services
era un comando "nascosto" in Homebrew. Ce n'erano alcuni che non erano presentibrew help
nell'output. Come i comandi non documentati sono soliti fare, è andato via nel repository ufficiale ed è diventato un " comando esterno " mantenuto in un altro repository aggiuntivo (in questo caso un riassunto in quanto è così semplice).
Puoi installarlo nella tua configurazione di 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 creare un file plist per esso. 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>
Basta cambiare il {your_username}
tuo nome utente reale quindi eseguire:
launchctl load ~/Library/LaunchAgents/org.mongodb.mongod.plist
per registrare il plist con launchd. Ora puoi avviare e interrompere MongoDB con:
launchctl start org.mongodb.mongod
launchctl stop org.mongodb.mongod
Si noti che la soluzione di plist sopra è stata presa da questa eccellente risposta Stack Overflow .