Skip to content

Instantly share code, notes, and snippets.

@e0da
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e0da/e1475ec3b032c02f9af5 to your computer and use it in GitHub Desktop.
Save e0da/e1475ec3b032c02f9af5 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Example usage:
# lctl stop mysql
# lctl start solr
# lctl restart rabbitmq
# lctl rabbitmq <- no action argument is equivalent to a restart argument
set -ex
if [ -z "$2" ]; then
command=restart
job=$1
else
command=$1
job=$2
fi
start_or_stop() {
local job_name
launchctl list | grep $job | awk '{print $3}' |
while read job_name; do
launchctl $command $job_name
done
}
case $command in
start|stop)
start_or_stop
;;
restart)
command=stop
start_or_stop
command=start
start_or_stop
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment