134 lines
4.8 KiB
Bash
Executable File

#!/bin/bash
GITLAB_HOST=${GITLAB_HOST:-localhost}
GITLAB_EMAIL=${GITLAB_EMAIL:-gitlab@localhost}
GITLAB_SUPPORT=${GITLAB_SUPPORT:-support@localhost}
REDIS_HOST=${REDIS_HOST:-localhost}
REDIS_PORT=${REDIS_PORT:-6379}
UNICORN_WORKERS=${UNICORN_WORKERS:-2}
SIDEKIQ_CONCURRENCY=${SIDEKIQ_CONCURRENCY:-5}
DB_HOST=${DB_HOST:-localhost}
DB_NAME=${DB_NAME:-gitlabhq_production}
DB_USER=${DB_USER:-root}
DB_PASS=${DB_PASS:-}
DB_INIT=${DB_INIT:-}
DB_POOL=${DB_POOL:-5}
# start supervisord
/usr/bin/supervisord
# start mysql server if ${DB_HOST} is localhost
if [ "${DB_HOST}" == "localhost" ]; then
if [ ! -d /var/lib/mysql/mysql ]; then
DB_INIT="yes"
mysql_install_db --user=mysql
fi
cat > /etc/supervisor/conf.d/mysqld.conf <<EOF
[program:mysqld]
priority=20
directory=/tmp
command=/usr/bin/mysqld_safe
user=root
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stderr_logfile=/var/log/supervisor/%(program_name)s.log
EOF
supervisorctl update
sleep 3
if [ "${DB_INIT}" == "yes" ]; then
echo 'CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;' | mysql -uroot
echo 'GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'root'@'localhost';' | mysql -uroot
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 <<EOF
[program:redis-server]
priority=20
directory=/tmp
command=/usr/bin/redis-server /etc/redis/redis.conf
user=redis
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stderr_logfile=/var/log/supervisor/%(program_name)s.log
EOF
supervisorctl update
fi
# configure git for the 'git' user
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "${GITLAB_EMAIL}"
sudo -u git -H git config --global core.autocrlf input
# configure server url
sudo -u git -H sed 's/host: localhost/host: '${GITLAB_HOST}'/' -i /home/git/gitlab/config/gitlab.yml
sudo -u git -H sed 's/email_from: gitlab@localhost/email_from: '${GITLAB_EMAIL}'/' -i /home/git/gitlab/config/gitlab.yml
sudo -u git -H sed 's/support_email: support@localhost/support_email: '${GITLAB_SUPPORT}'/' -i /home/git/gitlab/config/gitlab.yml
# configure database
sudo -u git -H sed 's/{{DB_HOST}}/'${DB_HOST}'/' -i /home/git/gitlab/config/database.yml
sudo -u git -H sed 's/{{DB_NAME}}/'${DB_NAME}'/' -i /home/git/gitlab/config/database.yml
sudo -u git -H sed 's/{{DB_USER}}/'${DB_USER}'/' -i /home/git/gitlab/config/database.yml
sudo -u git -H sed 's/{{DB_PASS}}/'${DB_PASS}'/' -i /home/git/gitlab/config/database.yml
sudo -u git -H sed 's/{{DB_POOL}}/'${DB_POOL}'/' -i /home/git/gitlab/config/database.yml
# configure sidekiq
sudo -u git -H sed 's/{{SIDEKIQ_CONCURRENCY}}/'${SIDEKIQ_CONCURRENCY}'/' -i /home/git/gitlab/config/sidekiq.yml
# configure redis
sudo -u git -H sed 's/redis.example.com:6379/'${REDIS_HOST}':'${REDIS_PORT}'/' -i /home/git/gitlab/config/resque.yml
# configure gitlab-shell
sudo -u git -H sed 's/host: 127.0.0.1/host: '${REDIS_HOST}'/' -i /home/git/gitlab-shell/config.yml
sudo -u git -H sed 's/port: 6379/port: '${REDIS_PORT}'/' -i /home/git/gitlab-shell/config.yml
# configure unicorn workers
sed 's/worker_processes 2/worker_processes '${UNICORN_WORKERS}'/' -i /home/git/gitlab/config/unicorn.rb
# make sure /home/git/repositories/ has the right permissions in case it is mounted as a volume.
sudo chmod ug+rwX,o-rwx /home/git/repositories/
sudo chmod ug-s /home/git/repositories/
find /home/git/repositories/ -type d -print0 | sudo xargs -0 chmod g+s
chown git:git /home/git/repositories
# make sure /home/git/gitlab-satellites/ has the right permissions in case it is mounted as a volume.
sudo chmod ug+rwX,o-rwx /home/git/gitlab-satellites/
sudo chmod ug-s /home/git/gitlab-satellites/
find /home/git/gitlab-satellites/ -type d -print0 | sudo xargs -0 chmod g+s
chown git:git /home/git/gitlab-satellites
# make sure /home/git/.ssh/ has the right permissions in case it is mounted as a volume.
touch /home/git/.ssh/authorized_keys
chmod 700 /home/git/.ssh
chmod 600 /home/git/.ssh/authorized_keys
chown -R git:git /home/git/.ssh
cd /home/git/gitlab/
# reset the database if the --db-init switch was given.
if [ "$DB_INIT" == "yes" ]; then
sudo -u git -H force=yes bundle exec rake gitlab:setup RAILS_ENV=production
fi
# start the gitlab application
# sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
/etc/init.d/gitlab start
# create satellite directories
sudo -u git -H bundle exec rake gitlab:satellites:create RAILS_ENV=production
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
# kickstart the rails application
wget "http://localhost" -O /dev/null
# watch the access logs
tail -F /var/log/nginx/gitlab_access.log