2018-04-08 20:49:07 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2018-06-03 22:11:12 +00:00
|
|
|
flags=""
|
2018-04-08 20:49:07 +00:00
|
|
|
|
2018-06-03 22:11:12 +00:00
|
|
|
print_help() {
|
2018-04-08 20:49:07 +00:00
|
|
|
echo "
|
|
|
|
Pleroma Maintenance Script
|
|
|
|
|
|
|
|
Usage:
|
2018-06-03 22:11:12 +00:00
|
|
|
$0 [action]
|
2018-04-08 20:49:07 +00:00
|
|
|
|
|
|
|
Actions:
|
2018-06-03 22:11:12 +00:00
|
|
|
build Rebuild the pleroma container
|
2018-04-08 20:49:07 +00:00
|
|
|
|
2018-06-03 22:11:12 +00:00
|
|
|
start / up Start pleroma and sibling services
|
2018-04-08 20:49:07 +00:00
|
|
|
|
2018-06-03 22:11:12 +00:00
|
|
|
stop / down Stop pleroma and sibling services
|
|
|
|
|
|
|
|
restart Executes #stop and #start respectively.
|
|
|
|
|
|
|
|
status / ps Show the current container status
|
2018-04-08 20:49:07 +00:00
|
|
|
|
2018-06-03 22:11:12 +00:00
|
|
|
logs Show the current container logs
|
|
|
|
|
|
|
|
enter Enter the pleroma container for debugging/maintenance
|
|
|
|
"
|
2018-04-08 20:49:07 +00:00
|
|
|
}
|
|
|
|
|
2018-06-03 22:11:12 +00:00
|
|
|
render_template() {
|
|
|
|
m4 $flags docker-compose.m4 | awk 'NF'
|
2018-04-08 20:49:07 +00:00
|
|
|
}
|
|
|
|
|
2018-06-03 22:11:12 +00:00
|
|
|
docker_compose() {
|
|
|
|
render_template | docker-compose -f - "$@"
|
2018-04-08 20:49:07 +00:00
|
|
|
}
|
|
|
|
|
2018-06-03 22:11:12 +00:00
|
|
|
load_env() {
|
|
|
|
if [[ ! -f .env ]]; then
|
|
|
|
echo "Please create a .env file first"
|
|
|
|
echo "(Copy .env.dist to .env for a template)"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
while read -r line; do
|
|
|
|
if [[ "$line" == \#* ]] || [[ -z "$line" ]]; then
|
|
|
|
continue;
|
|
|
|
fi
|
|
|
|
|
|
|
|
export "${line?}"
|
|
|
|
flags="-D__${line?} $flags"
|
|
|
|
done < .env
|
2018-04-08 20:49:07 +00:00
|
|
|
}
|
|
|
|
|
2018-06-03 22:11:12 +00:00
|
|
|
action__start() { docker_compose up --remove-orphans -d; }
|
|
|
|
action__up() { action__start; }
|
|
|
|
action__stop() { docker_compose down; }
|
|
|
|
action__down() { action__stop; }
|
|
|
|
action__restart() { action__stop; action__start; }
|
|
|
|
action__logs() { docker_compose logs -f; }
|
|
|
|
action__build() { docker_compose build --build-arg __BUST_CACHE="$(date +%s)" server; }
|
|
|
|
action__enter() { docker_compose exec server ash; }
|
|
|
|
action__status() { docker_compose ps; }
|
|
|
|
action__ps() { action__status; }
|
|
|
|
action__debug() { render_template; }
|
|
|
|
action__lint() { render_template | jq; }
|
2018-04-08 20:49:07 +00:00
|
|
|
|
|
|
|
if [[ -z "$1" ]]; then
|
|
|
|
print_help
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-06-03 22:11:12 +00:00
|
|
|
load_env
|
|
|
|
|
|
|
|
actions=(build update purge start up stop down restart logs enter status ps debug lint)
|
|
|
|
if [[ ${actions[*]} =~ ${1} ]]; then
|
|
|
|
"action__${1}"
|
|
|
|
else
|
2018-04-08 20:49:07 +00:00
|
|
|
print_help
|
|
|
|
exit 1
|
2018-06-03 22:11:12 +00:00
|
|
|
fi
|