pleroma-docker/pleroma.sh

110 lines
1.9 KiB
Bash
Raw Normal View History

2018-04-07 20:29:55 +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:
2018-04-08 15:04:06 +00:00
$0 [action] [flags]
2018-04-07 20:29:55 +00:00
Actions:
build Build the pleroma container and all dependencies
configure Runs the interactive configuration script
run Start pleroma and sibling services
stop Stop pleroma and sibling services
2018-04-08 15:04:06 +00:00
logs Show the current container logs
2018-04-07 20:29:55 +00:00
"
}
function run_dockerized {
2018-04-08 15:04:06 +00:00
log_info "Stopping existing containers (if any)"
2018-04-07 20:29:55 +00:00
docker-compose down
2018-04-08 15:04:06 +00:00
log_info "Rebuilding images"
2018-04-07 20:29:55 +00:00
docker-compose build
2018-04-08 15:04:06 +00:00
log_info "Running action '$1'"
2018-04-07 20:29:55 +00:00
docker-compose run server $1
log_info "Cleaning up.."
docker-compose down
}
function action__build {
run_dockerized "build"
log_ok "Done"
}
function action__configure {
run_dockerized "configure"
log_ok "Done"
}
function action__run {
2018-04-08 15:04:06 +00:00
log_info "Booting pleroma"
2018-04-07 20:29:55 +00:00
docker-compose up --remove-orphans -d
log_ok "Done"
}
function action__stop {
2018-04-08 15:04:06 +00:00
log_info "Stopping pleroma"
2018-04-07 20:29:55 +00:00
docker-compose down
log_ok "Done"
}
2018-04-08 15:04:06 +00:00
function action__logs {
docker-compose logs -f
}
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
2018-04-07 20:29:55 +00:00
if [[ -z "$1" ]]; then
log_error "No action provided."
print_help
exit 1
fi
2018-04-08 15:04:06 +00:00
prepare
2018-04-07 20:29:55 +00:00
case "$1" in
build) action__build;;
configure) action__configure;;
run) action__run;;
stop) action__stop;;
2018-04-08 15:04:06 +00:00
logs) action__logs;;
2018-04-07 20:29:55 +00:00
*)
log_error "The action '$1' is invalid."
print_help
exit 1
;;
esac
shift