pleroma-docker/pleroma

109 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
set -e
function log_generic { # $1: color, $2: prefix, $3: message #
echo -e "[$(tput setaf $1)$(tput bold)$2$(tput sgr0)] $3"
}
function log_error { # $1: message #
log_generic 1 ERR "$1"
}
function log_ok { # $1: message #
log_generic 2 "OK " "$1"
}
function log_info { # $1: message #
log_generic 4 INF "$1"
}
function print_help {
echo "
Pleroma Maintenance Script
Usage:
$0 [action] [flags]
Actions:
start Start pleroma and sibling services
stop Stop pleroma and sibling services
restart Executes #stop and #start respectively.
logs Show the current container logs
enter Enter the pleroma container for debugging/maintenance
"
}
function run_dockerized {
log_info "Stopping existing containers (if any)"
docker-compose down
log_info "Rebuilding images"
docker-compose build
log_info "Running action '$1'"
docker-compose run server $1
log_info "Cleaning up.."
docker-compose down
}
function action__start {
log_info "Booting pleroma"
docker-compose up --remove-orphans -d
log_ok "Done"
}
function action__stop {
log_info "Stopping pleroma"
docker-compose down
log_ok "Done"
}
function action__logs {
docker-compose logs -f
}
function action__build {
docker-compose build
}
function action__enter {
docker-compose exec server ash
}
function prepare {
log_info "Preparing script"
m4 docker-compose.m4 > docker-compose.yml
}
function cleanup {
log_info "Cleaning up"
rm docker-compose.yml
}
trap "cleanup" INT TERM EXIT
if [[ -z "$1" ]]; then
log_error "No action provided."
print_help
exit 1
fi
prepare
case "$1" in
build) action__build;;
start) action__start;;
stop) action__stop;;
restart) action__start; action__stop; ;;
logs) action__logs;;
enter) action__enter;;
*)
log_error "The action '$1' is invalid."
print_help
exit 1
;;
esac
shift