arzumy
5/16/2011 - 3:52 AM

Simple script to start/stop services using launchctl in OSX, with easy to remember service's name.

Simple script to start/stop services using launchctl in OSX, with easy to remember service's name.

#!/bin/bash
# usage: control (start|stop) service_shortname
# simple script by @arzumy

# I use this in my .bashrc
#
# alias start='~/scripts/control start '
# alias stop='~/scripts/control stop '
#
# Then I'll just type 'start mysql' to start mysql
# But make sure you've edited the pslist in ~/Library/LaunchAgents 
# by changing KeepAlive's value to false.

case "$2" in
mysql)  echo "$1 MySQL"
  launchctl "$1" com.mysql.mysqld
  ;;
pg)  echo "$1 postgresql"
  launchctl "$1" org.postgresql.postgres
  ;;
nginx) echo "$1 nginx"
  launchctl "$1" org.nginx
  ;;
mongo) echo "$1 mongodb"
  launchctl "$1" org.mongodb.mongod
  ;;
redis) echo "$1 redis"
  launchctl "$1" io.redis.redis-server
  ;;
memcached) echo "$1 memcached"
  launchctl "$1" com.danga.memcached
  ;;
fs) echo "$1 MySQL, nginx, mongodb, redis, memcached"
  launchctl "$1" com.mysql.mysqld
  launchctl "$1" org.nginx
  launchctl "$1" org.mongodb.mongod
  launchctl "$1" io.redis.redis-server
  launchctl "$1" com.danga.memcached
  ;;
*) echo "Service $2 not found"
  ;;
esac