relay/docker.sh

84 lines
1.8 KiB
Bash
Raw Permalink Normal View History

2022-05-06 07:04:51 +00:00
#!/usr/bin/env bash
case $1 in
install)
2024-04-02 16:32:49 +00:00
if [[ -z ${2#$} ]]; then
host=127.0.0.1
else
host=$2
fi
if [[ -z ${3#$} ]]; then
port=8080
else
port=$3
fi
2022-05-06 07:04:51 +00:00
docker build -f Dockerfile -t activityrelay . && \
docker volume create activityrelay-data && \
2024-04-02 16:32:49 +00:00
docker run -it -p target=8080,published=${host}:${port} -v activityrelay-data:/data --name activityrelay activityrelay
2022-05-06 07:04:51 +00:00
;;
uninstall)
docker stop activityrelay && \
docker container rm activityrelay && \
docker volume rm activityrelay-data && \
docker image rm activityrelay
;;
start)
docker start activityrelay
;;
stop)
docker stop activityrelay
;;
2024-04-02 16:32:49 +00:00
restart)
docker restart activityrelay
;;
2022-05-06 07:04:51 +00:00
manage)
shift
docker exec -it activityrelay python3 -m relay "$@"
;;
shell)
docker exec -it activityrelay bash
;;
rescue)
docker run -it --rm --entrypoint bash -v activityrelay-data:/data activityrelay
;;
edit)
if [ -z ${EDITOR} ]; then
echo "EDITOR environmental variable not set"
exit
fi
CONFIG="/tmp/relay-$(date +"%T").yaml"
docker cp activityrelay:/data/relay.yaml $CONFIG && \
$EDITOR $CONFIG && \
docker cp $CONFIG activityrelay:/data/relay.yaml && \
rm $CONFIG
;;
*)
COLS="%-22s %s\n"
echo "Valid commands:"
2024-04-01 21:29:27 +00:00
2022-05-06 07:04:51 +00:00
printf "$COLS" "- start" "Run the relay in the background"
printf "$COLS" "- stop" "Stop the relay"
printf "$COLS" "- manage <cmd> [args]" "Run a relay management command"
printf "$COLS" "- edit" "Edit the relay's config in \$EDITOR"
printf "$COLS" "- shell" "Drop into a bash shell on the running container"
printf "$COLS" "- rescue" "Drop into a bash shell on a temp container with the data volume mounted"
2024-04-02 16:32:49 +00:00
printf "$COLS" "- install [address] [port]" "Build the image, create a new container and volume, and run relay setup"
2022-05-06 07:04:51 +00:00
printf "$COLS" "- uninstall" "Delete the relay image, container, and volume"
;;
esac