Skip to content

Instantly share code, notes, and snippets.

@gorenje
Created February 3, 2011 10:02
Show Gist options
  • Save gorenje/809297 to your computer and use it in GitHub Desktop.
Save gorenje/809297 to your computer and use it in GitHub Desktop.
dbctl
function _funct_dbctl {
local action dbname logfile cmd
action=$1 ; shift ; dbname=$1 ; logfile=""
case $dbname in
mysql)
dbname="org.macports.mysql5"
;;
mongo)
echo "launchctl load /opt/local/etc/LaunchDaemons/org.macports.mongodb" | sudo bash 2>/dev/null
dbname="org.macports.mongod"
logfile="/opt/local/var/log/mongodb/error.log /opt/local/var/log/mongodb/output.log"
;;
couch)
dbname="org.apache.couchdb"
logfile="/opt/local/var/log/couchdb/couch.log"
;;
*)
echo "Unknown '${dbname}' DB, doing nothing"
return
esac
case $action in
start)
cmd="start ${dbname}"
;;
stop)
cmd="stop ${dbname}"
;;
*)
echo "Unknown '${action}' Action, doing nothing"
return
esac
echo "launchctl ${cmd}" | sudo bash
echo "launchctl list | grep ${dbname}" | sudo bash
if [ "$logfile" != "" -a "$action" != "stop" ] ; then
echo "Tailgating ${logfile} ..."
tail -f ${logfile}
fi
}
alias dbctl=_funct_dbctl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment