|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +function sigterm_handler() { |
| 5 | + echo "SIGTERM signal received, try to gracefully shutdown all services..." |
| 6 | + gitlab-ctl stop |
| 7 | +} |
| 8 | + |
| 9 | +function failed_pg_upgrade() { |
| 10 | + echo 'Upgrading the existing database to 9.6 failed and was reverted.' |
| 11 | + echo 'Please check the output, and open an issue at:' |
| 12 | + echo 'https://gitlab.com/gitlab-org/omnibus-gitlab/issues' |
| 13 | + echo 'If you would like to restart the instance without attempting to' |
| 14 | + echo 'upgrade, add the following to your docker command:' |
| 15 | + echo '-e GITLAB_SKIP_PG_UPGRADE=true' |
| 16 | + exit 1 |
| 17 | +} |
| 18 | + |
| 19 | +trap "sigterm_handler; exit" TERM |
| 20 | + |
| 21 | +source /RELEASE |
| 22 | +echo "Thank you for using GitLab Docker Image!" |
| 23 | +echo "Current version: $RELEASE_PACKAGE=$RELEASE_VERSION" |
| 24 | +echo "" |
| 25 | +if [[ "$PACKAGECLOUD_REPO" == "unstable" ]]; then |
| 26 | + echo "You are using UNSTABLE version of $RELEASE_PACKAGE!" |
| 27 | + echo "" |
| 28 | +fi |
| 29 | +echo "Configure GitLab for your system by editing /etc/gitlab/gitlab.rb file" |
| 30 | +echo "And restart this container to reload settings." |
| 31 | +echo "To do it use docker exec:" |
| 32 | +echo |
| 33 | +echo " docker exec -it gitlab vim /etc/gitlab/gitlab.rb" |
| 34 | +echo " docker restart gitlab" |
| 35 | +echo |
| 36 | +echo "For a comprehensive list of configuration options please see the Omnibus GitLab readme" |
| 37 | +echo "https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md" |
| 38 | +echo |
| 39 | +echo "If this container fails to start due to permission problems try to fix it by executing:" |
| 40 | +echo |
| 41 | +echo " docker exec -it gitlab update-permissions" |
| 42 | +echo " docker restart gitlab" |
| 43 | +echo |
| 44 | +sleep 3s |
| 45 | + |
| 46 | +# Copy gitlab.rb for the first time |
| 47 | +if [[ ! -e /etc/gitlab/gitlab.rb ]]; then |
| 48 | + echo "Installing gitlab.rb config..." |
| 49 | + cp /opt/gitlab/etc/gitlab.rb.template /etc/gitlab/gitlab.rb |
| 50 | + chmod 0600 /etc/gitlab/gitlab.rb |
| 51 | +fi |
| 52 | + |
| 53 | +# Generate ssh host key for the first time |
| 54 | +if [[ ! -f /etc/gitlab/ssh_host_rsa_key ]]; then |
| 55 | + echo "Generating ssh_host_rsa_key..." |
| 56 | + ssh-keygen -f /etc/gitlab/ssh_host_rsa_key -N '' -t rsa |
| 57 | + chmod 0600 /etc/gitlab/ssh_host_rsa_key |
| 58 | +fi |
| 59 | +if [[ ! -f /etc/gitlab/ssh_host_ecdsa_key ]]; then |
| 60 | + echo "Generating ssh_host_ecdsa_key..." |
| 61 | + ssh-keygen -f /etc/gitlab/ssh_host_ecdsa_key -N '' -t ecdsa |
| 62 | + chmod 0600 /etc/gitlab/ssh_host_ecdsa_key |
| 63 | +fi |
| 64 | +if [[ ! -f /etc/gitlab/ssh_host_ed25519_key ]]; then |
| 65 | + echo "Generating ssh_host_ed25519_key..." |
| 66 | + ssh-keygen -f /etc/gitlab/ssh_host_ed25519_key -N '' -t ed25519 |
| 67 | + chmod 0600 /etc/gitlab/ssh_host_ed25519_key |
| 68 | +fi |
| 69 | + |
| 70 | +# Remove all services, the reconfigure will create them |
| 71 | +echo "Preparing services..." |
| 72 | +rm -f /opt/gitlab/service/* |
| 73 | +ln -s /opt/gitlab/sv/sshd /opt/gitlab/service |
| 74 | +ln -sf /opt/gitlab/embedded/bin/sv /opt/gitlab/init/sshd |
| 75 | +mkdir -p /var/log/gitlab/sshd |
| 76 | + |
| 77 | +# Start service manager |
| 78 | +echo "Starting services..." |
| 79 | +GITLAB_OMNIBUS_CONFIG= /opt/gitlab/embedded/bin/runsvdir-start & |
| 80 | + |
| 81 | +# Configure gitlab package |
| 82 | +# WARNING: |
| 83 | +# the preinst script has the database backup |
| 84 | +# It will not be executed, because all services are not yet started |
| 85 | +# They will be started when `reconfigure` is executed |
| 86 | +echo "Configuring GitLab package..." |
| 87 | +/var/lib/dpkg/info/${RELEASE_PACKAGE}.preinst upgrade |
| 88 | + |
| 89 | +echo "Configuring GitLab..." |
| 90 | +gitlab-ctl reconfigure |
| 91 | + |
| 92 | +# Make sure PostgreSQL is at the latest version. |
| 93 | +# If it fails, print a message with a workaround and exit |
| 94 | +if [ "${GITLAB_SKIP_PG_UPGRADE}" != true ]; then |
| 95 | + gitlab-ctl pg-upgrade -w || failed_pg_upgrade |
| 96 | +fi |
| 97 | + |
| 98 | +if [ -n "${GITLAB_POST_RECONFIGURE_SCRIPT+x}" ]; then |
| 99 | + echo "Runnning Post Reconfigure Script..." |
| 100 | + eval "${GITLAB_POST_RECONFIGURE_SCRIPT}" |
| 101 | +fi |
0 commit comments