2020-09-09 23:14:59 +01:00
|
|
|
#!/bin/bash -e
|
|
|
|
python -m lifecycle.wait_for_db
|
2020-10-03 19:36:36 +01:00
|
|
|
printf '{"event": "Bootstrap completed", "level": "info", "logger": "bootstrap", "command": "%s"}\n' "$@" > /dev/stderr
|
2021-05-13 19:11:49 +01:00
|
|
|
|
|
|
|
function check_if_root {
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
|
|
printf '{"event": "Not running as root, disabling permission fixes", "level": "info", "logger": "bootstrap", "command": "%s"}\n' "$@" > /dev/stderr
|
2021-05-13 21:55:35 +01:00
|
|
|
$1
|
2021-05-13 19:11:49 +01:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
SOCKET="/var/run/docker.sock"
|
2021-06-09 14:56:12 +01:00
|
|
|
GROUP="authentik"
|
2021-05-13 19:11:49 +01:00
|
|
|
if [[ -e "$SOCKET" ]]; then
|
|
|
|
# Get group ID of the docker socket, so we can create a matching group and
|
|
|
|
# add ourselves to it
|
|
|
|
DOCKER_GID=$(stat -c '%g' $SOCKET)
|
2021-09-09 14:24:35 +01:00
|
|
|
# Ensure group for the id exists
|
2021-05-13 23:50:20 +01:00
|
|
|
getent group $DOCKER_GID || groupadd -f -g $DOCKER_GID docker
|
2021-05-13 19:11:49 +01:00
|
|
|
usermod -a -G $DOCKER_GID authentik
|
2021-09-09 14:24:35 +01:00
|
|
|
# since the name of the group might not be docker, we need to lookup the group id
|
|
|
|
GROUP_NAME=$(getent group $DOCKER_GID | sed 's/:/\n/g' | head -1)
|
|
|
|
GROUP="authentik:${GROUP_NAME}"
|
2021-05-13 19:11:49 +01:00
|
|
|
fi
|
|
|
|
# Fix permissions of backups and media
|
|
|
|
chown -R authentik:authentik /media /backups
|
2021-06-09 14:56:12 +01:00
|
|
|
chpst -u authentik:$GROUP env HOME=/authentik $1
|
2021-05-13 19:11:49 +01:00
|
|
|
}
|
|
|
|
|
2021-10-05 19:45:18 +01:00
|
|
|
MODE_FILE="/tmp/authentik-mode"
|
|
|
|
|
2020-09-09 23:14:59 +01:00
|
|
|
if [[ "$1" == "server" ]]; then
|
2021-10-05 19:45:18 +01:00
|
|
|
echo "server" > $MODE_FILE
|
2021-04-18 13:47:50 +01:00
|
|
|
python -m lifecycle.migrate
|
2021-05-02 23:49:16 +01:00
|
|
|
/authentik-proxy
|
2020-09-09 23:14:59 +01:00
|
|
|
elif [[ "$1" == "worker" ]]; then
|
2021-10-05 19:45:18 +01:00
|
|
|
echo "worker" > $MODE_FILE
|
2021-05-13 21:55:35 +01:00
|
|
|
check_if_root "celery -A authentik.root.celery worker --autoscale 3,1 -E -B -s /tmp/celerybeat-schedule -Q authentik,authentik_scheduled,authentik_events"
|
2020-10-03 19:36:36 +01:00
|
|
|
elif [[ "$1" == "backup" ]]; then
|
|
|
|
python -m manage dbbackup --clean
|
|
|
|
elif [[ "$1" == "restore" ]]; then
|
|
|
|
python -m manage dbrestore ${@:2}
|
|
|
|
elif [[ "$1" == "bash" ]]; then
|
|
|
|
/bin/bash
|
2021-06-09 14:50:32 +01:00
|
|
|
elif [[ "$1" == "test" ]]; then
|
|
|
|
pip install --no-cache -r requirements-dev.txt
|
2021-06-09 15:03:51 +01:00
|
|
|
touch /unittest.xml
|
|
|
|
chown authentik:authentik /unittest.xml
|
2021-06-09 14:50:32 +01:00
|
|
|
check_if_root "python -m manage test authentik"
|
2021-10-05 19:45:18 +01:00
|
|
|
elif [[ "$1" == "healthcheck" ]]; then
|
|
|
|
mode=$(cat $MODE_FILE)
|
2021-10-05 20:03:54 +01:00
|
|
|
if [[ $mode == "server" ]]; then
|
2021-10-05 21:19:33 +01:00
|
|
|
curl --user-agent "goauthentik.io lifecycle Healthcheck" -I http://localhost:9000/-/health/ready/
|
2021-10-05 19:45:18 +01:00
|
|
|
elif [[ $mode == "worker" ]]; then
|
|
|
|
celery -A authentik.root.celery inspect ping -d celery@$HOSTNAME
|
|
|
|
fi
|
2020-09-09 23:14:59 +01:00
|
|
|
else
|
|
|
|
python -m manage "$@"
|
|
|
|
fi
|