1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #!/usr/bin/env sh
- if [ $# -lt 1 ] || [ "$1" == "help" ] || [ "$1" == "h" ]
- then
- echo "usage: $0 (help|status|clean|run|logs) [container-name]"
- echo " help - print this message"
- echo " status - report whether a container named container-name can be found, and whether or not it is running"
- echo " clean - kill and remove any existing containers matching container-name"
- echo " run - kill and remove any existing containers matching container-name, build the current directory into a new image, and deploy a new container container-name"
- echo " logs - tail the logs of the container named container-name, equivalent to docker logs -f container-name"
- echo " container-name defaults to rollbot3-instance"
- echo " Run as root to ensure docker can be used, or set FORCE_NOROOT=* to force the script to run anyway."
- exit 1
- fi
- if [ "$EUID" -ne 0 ] && [ -z "$FORCE_NOROOT" ]
- then
- echo "$0 must be run as root to use docker. Set FORCE_NOROOT=* to force the script to run anyway."
- exit 1
- fi
- if [ $# -gt 1 ]
- then
- CONTAINER_NAME=$2
- else
- CONTAINER_NAME="rollbot3-instance"
- fi
- status_check() {
- docker inspect -f '{{.State.Running}}' $CONTAINER_NAME 2> /dev/null
- }
- clean_container() {
- STATUS=$(status_check)
- if [ "$STATUS" = "true" ]
- then
- echo "Container $CONTAINER_NAME is running and will be stopped and removed."
- docker kill $CONTAINER_NAME
- docker rm $CONTAINER_NAME
- elif [ "$STATUS" = "false" ]
- then
- echo "Container $CONTAINER_NAME is stopped and will be removed."
- docker rm $CONTAINER_NAME
- else
- echo "No existing container $CONTAINER_NAME could be found, no cleanup will be performed."
- fi
- }
- case $1 in
- "l"|"logs")
- STATUS=$(status_check)
- if [ "$STATUS" = "true" ] || [ "$STATUS" = "false" ]
- then
- docker logs -f $CONTAINER_NAME
- else
- echo "No existing container $CONTAINER_NAME could be found."
- fi
- ;;
- "r"|"run")
- clean_container
- echo "Building rollbot3 image as rollbot3:latest"
- docker build -t rollbot3:latest .
- echo "Executing new container $CONTAINER_NAME using rollbot3:latest"
- docker run -p6070:6070 -v ./config:/rollbot-config --name $CONTAINER_NAME -d rollbot3
- echo "Rollbot endpoint accessible at http://localhost:6070/rollbot"
- ;;
- "c"|"clean")
- clean_container
- ;;
- "s"|"status")
- STATUS=$(status_check)
- if [ "$STATUS" = "true" ]
- then
- echo "Existing container $CONTAINER_NAME is running."
- elif [ "$STATUS" = "false" ]
- then
- echo "Existing container $CONTAINER_NAME is stopped."
- else
- echo "No existing container $CONTAINER_NAME could be found."
- fi
- ;;
- *)
- echo "Unknown option $1, must be one of help, status, clean, run, logs."
- exit 1
- ;;
- esac
|