2018-04-08 20:49:07 +00:00
|
|
|
#!/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 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 {
|
2018-04-09 09:55:52 +00:00
|
|
|
docker-compose pull
|
|
|
|
docker-compose build --build-arg __BUST_CACHE="$(date)" server
|
2018-04-08 20:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
2018-04-08 23:23:36 +00:00
|
|
|
[[ -f docker-compose.yml ]] && rm docker-compose.yml
|
2018-04-08 20:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;;
|
2018-04-09 08:55:05 +00:00
|
|
|
restart) action__stop; action__start; ;;
|
2018-04-08 20:49:07 +00:00
|
|
|
logs) action__logs;;
|
|
|
|
enter) action__enter;;
|
|
|
|
*)
|
|
|
|
log_error "The action '$1' is invalid."
|
|
|
|
print_help
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|