Skip to content

Instantly share code, notes, and snippets.

@jamesmcdonald
Created December 3, 2019 13:45
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 jamesmcdonald/a231b9318fc750a971b89b86d1bd8046 to your computer and use it in GitHub Desktop.
Save jamesmcdonald/a231b9318fc750a971b89b86d1bd8046 to your computer and use it in GitHub Desktop.
Cerebro runner for all your cerebro needs
function cerebro() {
docker network inspect cerebro >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo -n "Creating cerebro network: "
docker network create cerebro
if [[ $? -ne 0 ]]; then
echo "Failed to create network, aborting" >&2
return
fi
fi
# Check if we need to start a cerebro
if [[ -z $(docker ps -q -f name=cerebro) ]]; then
# Container not running
if [[ -n $(docker ps -qa -f name=cerebro) ]]; then
echo -n "Deleting stale cerebro container: "
docker rm -f cerebro
if [[ $? -ne 0 ]]; then
echo "Failed to delete container, aborting" >&2
return
fi
fi
# Start the container
echo -n "Running container: "
docker run -d --name cerebro --network cerebro yannart/cerebro
echo -n "Letting the container start... "
sleep 5
echo "done"
fi
local ip=$(docker inspect cerebro -f {{.NetworkSettings.Networks.cerebro.IPAddress}})
local arg=$1; shift
if [[ $arg == "-s" ]]; then
local host=$1
local command="ssh -o ExitOnForwardFailure=yes -N -f -L 172.17.0.1:9200:127.0.0.1:9200 $host"
echo "Starting $command"
$command
echo To kill tunnel: kill $(pgrep -f "$command")
x-www-browser "http://$ip:9000/#/overview?host=http://172.17.0.1:9200"
elif [[ $arg == "" ]]; then
x-www-browser http://$ip:9000/
else
x-www-browser "http://$ip:9000/#/overview?host=$arg"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment