Skip to content

Instantly share code, notes, and snippets.

@michaelstephens
Created July 9, 2018 18:29
Show Gist options
  • Save michaelstephens/f7017b3837f003ee1f69cd1387bf1058 to your computer and use it in GitHub Desktop.
Save michaelstephens/f7017b3837f003ee1f69cd1387bf1058 to your computer and use it in GitHub Desktop.
ASDF Start Script
function asdf() {
case $1 in
"start")
case $2 in
"psql"|"postgres")
pg_ctl -D `asdf where postgres $(asdf current postgres)`/data start > /dev/null 2>&1
echo "[STARTED] Postgres `asdf current postgres`"
;;
"redis"|"redis-server")
`asdf which redis`-server /usr/local/etc/redis.conf
echo "[STARTED] Redis `asdf current redis`"
;;
"es"|"elasticsearch")
`asdf which elasticsearch` -p /tmp/elasticsearch-pid -d
echo "[STARTED] Elasticsearch `asdf current elasticsearch`"
;;
"kibana")
nohup `echo $(asdf which kibana) --log-file $(asdf where kibana)/kibana.log` >/dev/null&
echo "[STARTED] Kibana `asdf current kibana`"
;;
"all")
asdf start postgres
asdf start redis
asdf start elasticsearch
asdf start kibana
;;
*)
echo "Plugin not found. Run \"asdf plugin-list\" to find available plugins."
;;
esac
;;
"stop")
case $2 in
"psql"|"postgres")
pg_ctl -D `asdf where postgres $(asdf current postgres)`/data stop > /dev/null 2>&1
echo "[STOPPED] Postgres `asdf current postgres`"
;;
"redis"|"redis-server")
kill $(ps aux | grep "$(asdf which redis)" | awk '{print $2}')
echo "[STOPPED] Redis `asdf current redis`"
;;
"es"|"elasticsearch")
kill -SIGTERM $(cat /tmp/elasticsearch-pid | sed 's/%//')
echo "[STOPPED] Elasticsearch `asdf current elasticsearch`"
;;
"kibana")
kill $(ps aux | grep "$(asdf where kibana)" | awk '{print $2}')
echo "[STOPPED] Kibana `asdf current kibana`"
;;
"all")
asdf stop postgres
asdf stop redis
asdf stop elasticsearch
asdf start kibana
;;
*)
echo "Plugin not found. Run \"asdf plugin-list\" to find available plugins."
;;
esac
;;
"restart")
case $2 in
"psql"|"postgres")
asdf stop postgres
asdf start postgres
;;
"redis"|"redis-server")
asdf stop redis
asdf start redis
;;
"es"|"elasticsearch")
asdf stop elasticsearch
asdf start elasticsearch
;;
"kibana")
asdf stop kibana
asdf start kibana
;;
*)
echo "Plugin not found. Run \"asdf plugin-list\" to find available plugins."
;;
esac
;;
*)
~/.asdf/bin/asdf "$@"
;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment