Skip to content

Instantly share code, notes, and snippets.

@dgoodwin
Created February 26, 2016 14:15
Show Gist options
  • Save dgoodwin/3604bd3b454811969abb to your computer and use it in GitHub Desktop.
Save dgoodwin/3604bd3b454811969abb to your computer and use it in GitHub Desktop.
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
COMMAND="${1:-}"
NAME="${2:-}"
shift
shift
SERVER_ARGS="$@"
function usage() {
echo "Usage: originctl <create|launch> <server>"
exit 1
}
if [ -z "$NAME" ]; then usage; fi
if [ -z "$COMMAND" ]; then usage; fi
SERVER_DIR="$PWD/$NAME"
IP=$(ip route get 1 | awk '{print $NF;exit}')
HOSTNAME=$(hostname)
function create() {
if [ -d "$SERVER_DIR" ]; then
echo "$SERVER_DIR already exists"
exit 1
fi
mkdir -p $SERVER_DIR
sudo env PATH="$PATH" \
openshift start \
--hostname=$HOSTNAME \
--master=https://$IP:8443 \
--listen=https://$IP:8443 \
--latest-images \
--etcd-dir="$SERVER_DIR/openshift.local.etcd" \
--volume-dir="$SERVER_DIR/openshift.local.volumes" \
--write-config="$SERVER_DIR/openshift.local.config"
sudo chown -R $USER:$USER $SERVER_DIR
#mkdir -p go/{src,bin}
#CLONE_DIR="$SERVER_DIR/go/src/github.com/openshift/origin"
#git clone [email protected]:ironcladlou/origin.git $CLONE_DIR
#pushd $CLONE_DIR > /dev/null
#git remote add upstream https://github.com/openshift/origin.git
#git fetch upstream
#popd > /dev/null
echo "export KUBECONFIG=$SERVER_DIR/openshift.local.config/master/admin.kubeconfig" > $SERVER_DIR/.envrc
echo "source_env ../.." >> $SERVER_DIR/.envrc
pushd $SERVER_DIR > /dev/null
direnv allow .
popd > /dev/null
echo "Created server at $SERVER_DIR"
}
function launch() {
if [ ! -d "$SERVER_DIR" ]; then
echo "No server found at $SERVER_DIR"
exit 2
fi
sudo env "PATH=$PATH" \
openshift start \
--hostname=$HOSTNAME \
--master-config="$SERVER_DIR/openshift.local.config/master/master-config.yaml" \
--node-config="$SERVER_DIR/openshift.local.config/node-$HOSTNAME/node-config.yaml"
}
function reset() {
if [ ! -d "$SERVER_DIR" ]; then
echo "No server found at $SERVER_DIR"
exit 2
fi
set +e
if [ $(docker ps -aq | wc -l) -gt 0 ]; then
docker kill $(docker ps -aq)
docker rm -f $(docker ps -aq)
fi
if mount | grep -q 'volumes/pods'; then
mount | grep volumes/pods | awk '{ print $3 }' | xargs sudo umount
fi
sudo rm -rf $SERVER_DIR/openshift.local.etcd
sudo rm -rf $SERVER_DIR/openshift.local.volumes
set -e
}
if [ "$COMMAND" == "create" ]; then create; fi
if [ "$COMMAND" == "launch" ]; then launch; fi
if [ "$COMMAND" == "reset" ]; then reset; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment