#!/bin/bash set -e GITLAB_HOST=${GITLAB_HOST:-localhost} GITLAB_PORT=${GITLAB_PORT:-80} GITLAB_HTTPS=${GITLAB_HTTPS:-false} GITLAB_EMAIL=${GITLAB_EMAIL:-gitlab@localhost} GITLAB_SUPPORT=${GITLAB_SUPPORT:-support@localhost} GITLAB_SIGNUP=${GITLAB_SIGNUP:-false} GITLAB_BACKUPS=${GITLAB_BACKUPS:-disable} GITLAB_BACKUP_EXPIRY=${GITLAB_BACKUP_EXPIRY:-} GITLAB_SHELL_SSH_PORT=${GITLAB_SHELL_SSH_PORT:-22} REDIS_HOST=${REDIS_HOST:-localhost} REDIS_PORT=${REDIS_PORT:-6379} UNICORN_WORKERS=${UNICORN_WORKERS:-2} UNICORN_TIMEOUT=${UNICORN_TIMEOUT:-60} SIDEKIQ_CONCURRENCY=${SIDEKIQ_CONCURRENCY:-5} DB_TYPE=${DB_TYPE:-mysql} DB_HOST=${DB_HOST:-localhost} DB_PORT=${DB_PORT:-} DB_NAME=${DB_NAME:-gitlabhq_production} DB_USER=${DB_USER:-root} DB_PASS=${DB_PASS:-} DB_INIT=${DB_INIT:-} DB_POOL=${DB_POOL:-10} SMTP_DOMAIN=${SMTP_DOMAIN:-www.gmail.com} SMTP_HOST=${SMTP_HOST:-smtp.gmail.com} SMTP_PORT=${SMTP_PORT:-587} SMTP_USER=${SMTP_USER:-} SMTP_PASS=${SMTP_PASS:-} SMTP_STARTTLS=${SMTP_STARTTLS:-true} case "${DB_TYPE}" in mysql) DB_PORT=${DB_PORT:-3306} ;; postgres) DB_PORT=${DB_PORT:-5432} ;; *) echo "Unsupported database adapter. Available adapters are mysql and postgres." && exit 1 ;; esac case "${GITLAB_BACKUPS}" in daily|monthly) GITLAB_BACKUP_EXPIRY=${GITLAB_BACKUP_EXPIRY:-604800} ;; disable|*) GITLAB_BACKUP_EXPIRY=${GITLAB_BACKUP_EXPIRY:-0} ;; esac # generate a password for root. ROOT_PASSWORD=$(pwgen -c -n -1 12) echo "root:$ROOT_PASSWORD" | chpasswd echo User: root Password: $ROOT_PASSWORD # start supervisord /usr/bin/supervisord # over write default configuration templates if [ -d /home/git/data/config ]; then chown -R git:git /home/git/data/config cd /home/git/data/config [ -f nginx/gitlab ] && cp nginx/gitlab /etc/nginx/sites-available/gitlab [ -f gitlab-shell/config.yml ] && sudo -u git -H cp gitlab-shell/config.yml /home/git/gitlab-shell/config.yml [ -f gitlabhq/gitlab.yml ] && sudo -u git -H cp gitlabhq/gitlab.yml /home/git/gitlab/config/gitlab.yml [ -f gitlabhq/resque.yml ] && sudo -u git -H cp gitlabhq/resque.yml /home/git/gitlab/config/resque.yml [ -f gitlabhq/database.yml ] && sudo -u git -H cp gitlabhq/database.yml /home/git/gitlab/config/database.yml [ -f gitlabhq/sidekiq.yml ] && sudo -u git -H cp gitlabhq/sidekiq.yml /home/git/gitlab/config/sidekiq.yml [ -f gitlabhq/unicorn.rb ] && sudo -u git -H cp gitlabhq/unicorn.rb /home/git/gitlab/config/unicorn.rb [ -f gitlabhq/rack_attack.rb ] && sudo -u git -H cp gitlabhq/rack_attack.rb /home/git/gitlab/config/initializers/rack_attack.rb [ -f gitlabhq/smtp_settings.rb ] && sudo -u git -H cp gitlabhq/smtp_settings.rb /home/git/gitlab/config/initializers/smtp_settings.rb fi sed 's/{{YOUR_SERVER_FQDN}}/localhost/' -i /etc/nginx/sites-available/gitlab supervisorctl restart nginx # start mysql server if ${DB_HOST} is localhost if [ "${DB_HOST}" == "localhost" ]; then if [ "${DB_TYPE}" == "postgres" ]; then echo "DB_TYPE 'postgres' is not supported internally. Please provide DB_HOST." exit 1 fi cat > /etc/supervisor/conf.d/mysqld.conf </dev/null 2>&1 do timeout=$(expr $timeout - 1) if [ $timeout -eq 0 ]; then echo "Failed to start mysql server" exit 1 fi sleep 1 done if ! echo "USE ${DB_NAME}" | mysql -uroot ${DB_PASS:+-p$DB_PASS} >/dev/null 2>&1; then DB_INIT="yes" echo "CREATE DATABASE IF NOT EXISTS \`${DB_NAME}\` DEFAULT CHARACTER SET \`utf8\` COLLATE \`utf8_unicode_ci\`;" | mysql -uroot ${DB_PASS:+-p$DB_PASS} echo "GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON \`${DB_NAME}\`.* TO 'root'@'localhost';" | mysql -uroot ${DB_PASS:+-p$DB_PASS} fi fi if [ "${REDIS_HOST}" == "localhost" ]; then sed 's/daemonize yes/daemonize no/' -i /etc/redis/redis.conf cat > /etc/supervisor/conf.d/redis-server.conf < /tmp/cron.git < /tmp/cron.git < - Execute a rake task." echo " app:help - Displays the help" echo " [command] - Execute the specified linux command eg. bash." } case "$1" in app:start) gitlab_start ;; app:rake) shift 1 gitlab_rake $@ ;; app:help) gitlab_help ;; *) if [ -x $1 ]; then $1 else prog=$(which $1) if [ -n "${prog}" ] ; then shift 1 $prog $@ else gitlab_help fi fi ;; esac exit 0