-ctl pg-upgrade -w --skip-disk-check || failed_pg_upgrade
fi

if [ -n "${GITLAB_POST_RECONFIGURE_SCRIPT+x}" ]; then
  echo "Running Post Reconfigure Script..."
  eval "${GITLAB_POST_RECONFIGURE_SCRIPT}"
fi

if [ "${GITLAB_SKIP_TAIL_LOGS}" != 'true' ]; then
  # Tail all logs
  gitlab-ctl tail &
fi

# Wait for SIGTERM
wait
]; then
  # Tail all logs
  gitlab-ctl tail &
fi

# Wait for SIGTERM
wait
O_PG_UPGRADE}" != 'false' ]; then
    gitlab-ctl pg-upgrade -w --skip-disk-check || failed_pg_upgrade
fi

if [ -n "${GITLAB_POST_RECONFIGURE_SCRIPT+x}" ]; then
  echo "Running Post Reconfigure Script..."
  eval "${GITLAB_POST_RECONFIGURE_SCRIPT}"
fi

if [ "${GITLAB_SKIP_TAIL_LOGS}" != 'true' ]; then
  # Tail all logs
  gitlab-ctl tail &
fi

# Wait for SIGTERM
wait
hen
  # Tail all logs
  gitlab-ctl tail &
fi

# Wait for SIGTERM
wait
 for pg-upgrade,
# otherwise it must be true.
ATTEMPT_AUTO_PG_UPGRADE='true'

# Make sure PostgreSQL is at the latest version.
# If it fails, print a message with a workaround and exit
if [ "${GITLAB_SKIP_PG_UPGRADE}" != 'true' -a "${ATTEMPT_AUTO_PG_UPGRADE}" != 'false' ]; then
    gitlab-ctl pg-upgrade -w --skip-disk-check || failed_pg_upgrade
fi

if [ -n "${GITLAB_POST_RECONFIGURE_SCRIPT+x}" ]; then
  echo "Running Post Reconfigure Script..."
  eval "${GITLAB_POST_RECONFIGURE_SCRIPT}"
fi

if [ "${GITLAB_SKIP_TAIL_LOGS}" != 'true' ]; then
  # Tail all logs
  gitlab-ctl tail &
fi

# Wait for SIGTERM
wait
MNIBUS_CONFIG= /opt/gitlab/embedded/bin/runsvdir-start &

echo "Configuring GitLab..."
gitlab-ctl reconfigure

# This must be false when the opt-in PostgreSQL version is the default for pg-upgrade,
# otherwise it must be true.
ATTEMPT_AUTO_PG_UPGRADE='true'

# Make sure PostgreSQL is at the latest version.
# If it fails, print a message with a workaround and exit
if [ "${GITLAB_SKIP_PG_UPGRADE}" != 'true' -a "${ATTEMPT_AUTO_PG_UPGRADE}" != 'false' ]; then
    gitlab-ctl pg-upgrade -w --skip-disk-check || failed_pg_upgrade
fi

if [ -n "${GITLAB_POST_RECONFIGURE_SCRIPT+x}" ]; then
  echo "Running Post Reconfigure Script..."
  eval "${GITLAB_POST_RECONFIGURE_SCRIPT}"
fi

if [ "${GITLAB_SKIP_TAIL_LOGS}" != 'true' ]; then
  # Tail all logs
  gitlab-ctl tail &
fi

# Wait for SIGTERM
wait
Tail all logs
  gitlab-ctl tail &
fi

# Wait for SIGTERM
wait
_host_ecdsa_key..."
	ssh-keygen -f /etc/gitlab/ssh_host_ecdsa_key -N '' -t ecdsa
	chmod 0600 /etc/gitlab/ssh_host_ecdsa_key
fi
# sshd loads the keys from /etc/gitlab, but the GitLab backend looks for keys
# from within /etc/ssh
ln -fs /etc/gitlab/ssh_host_ecdsa_key /etc/ssh/ssh_host_ecdsa_key
ln -fs /etc/gitlab/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub

if [[ ! -f /etc/gitlab/ssh_host_ed25519_key ]]; then
	echo "Generating ssh_host_ed25519_key..."
	ssh-keygen -f /etc/gitlab/ssh_host_ed25519_key -N '' -t ed25519
	chmod 0600 /etc/gitlab/ssh_host_ed25519_key
fi
# sshd loads the keys from /etc/gitlab, but the GitLab backend looks for keys
# from within /etc/ssh
ln -fs /etc/gitlab/ssh_host_ed25519_key /etc/ssh/ssh_host_ed25519_key
ln -fs /etc/gitlab/ssh_host_ed25519_key.pub /etc/ssh/ssh_host_ed25519_key.pub


# Remove all services, the reconfigure will create them
echo "Preparing services..."
rm -f /opt/gitlab/service/*
ln -s /opt/gitlab/sv/sshd /opt/gitlab/service
ln -sf /opt/gitlab/embedded/bin/sv /opt/gitlab/init/sshd
mkdir -p /var/run/sshd
mkdir -p /var/log/gitlab/sshd
mkdir -p /var/log/gitlab/reconfigure

if [ -n "${GITLAB_PRE_RECONFIGURE_SCRIPT+x}" ]; then
  echo "Running Pre Reconfigure Script..."
  eval "${GITLAB_PRE_RECONFIGURE_SCRIPT}"
fi

# Start service manager
echo "Starting services..."
GITLAB_OMNIBUS_CONFIG= /opt/gitlab/embedded/bin/runsvdir-start &

echo "Configuring GitLab..."
gitlab-ctl reconfigure

# This must be false when the opt-in PostgreSQL version is the default for pg-upgrade,
# otherwise it must be true.
ATTEMPT_AUTO_PG_UPGRADE='true'

# Make sure PostgreSQL is at the latest version.
# If it fails, print a message with a workaround and exit
if [ "${GITLAB_SKIP_PG_UPGRADE}" != 'true' -a "${ATTEMPT_AUTO_PG_UPGRADE}" != 'false' ]; th