mirror of
https://github.com/sameersbn/docker-gitlab.git
synced 2026-01-18 13:58:25 +00:00
136 lines
3.7 KiB
Bash
Executable File
136 lines
3.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
usage() {
|
|
echo "Usage: $0 [OPTIONS]"
|
|
echo " -a, --server-url server url (default is gitlab)."
|
|
echo " -H, --db-host database hostname (default is localhost)."
|
|
echo " -d, --db-name database name (default is redmine)."
|
|
echo " -u, --db-user database username (default is root)."
|
|
echo " -p, --db-passwd database user password (default is no password)."
|
|
echo " -I --db-init initialize the database (resets any existing data in the database)"
|
|
echo " -h, --help print this help."
|
|
exit 1
|
|
}
|
|
|
|
SERVER_URL="gitlab"
|
|
DB_NAME="localhost"
|
|
DB_NAME="gitlabhq_production"
|
|
DB_USER="root"
|
|
DB_PASSWD=""
|
|
DB_INIT="no"
|
|
|
|
ARGS=$(getopt -o a:H:d:u:p:Ih -l "server-url:,db-host:,db-name:,db-user:,db-passwd:,db-init,help" -n "$0" -- "$@")
|
|
if [ $? -ne 0 ]; then
|
|
exit 1
|
|
fi
|
|
|
|
eval set -- "$ARGS"
|
|
while true; do
|
|
case "$1" in
|
|
-a|--server-url)
|
|
shift
|
|
SERVER_URL="${1}"
|
|
shift ;;
|
|
-H|--db-host)
|
|
shift
|
|
DB_HOST="${1}"
|
|
shift
|
|
;;
|
|
-d|--db-name)
|
|
shift
|
|
DB_NAME="${1}"
|
|
shift
|
|
;;
|
|
-u|--db-user)
|
|
shift
|
|
DB_USER="${1}"
|
|
shift
|
|
;;
|
|
-p|--db-passwd)
|
|
shift
|
|
DB_PASSWD="${1}"
|
|
shift
|
|
;;
|
|
-I|--db-init)
|
|
shift
|
|
DB_INIT="yes"
|
|
;;
|
|
-h|--help)
|
|
shift
|
|
usage
|
|
;;
|
|
--)
|
|
shift
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# start mysql server if ${DB_HOST} is localhost
|
|
if [ -z "${DB_HOST}" ] || [ "${DB_HOST}" == "localhost" ]; then
|
|
DB_HOST="localhost"
|
|
DB_USER="root"
|
|
DB_PASSWD=""
|
|
DB_INIT="yes"
|
|
|
|
mysql_install_db --user=mysql
|
|
/usr/bin/mysqld_safe &
|
|
sleep 3
|
|
|
|
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
|
|
|
|
# start ssh server
|
|
/usr/sbin/sshd
|
|
redis-server > /dev/null &
|
|
sleep 3
|
|
|
|
# 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@localhost"
|
|
sudo -u git -H git config --global core.autocrlf input
|
|
|
|
# configure server url
|
|
# sudo -u git -H sed 's/http:\/\/localhost/http:\/\/'${SERVER_URL}'/' -i /home/git/gitlab-shell/config.yml
|
|
sudo -u git -H sed 's/host: localhost/host: '${SERVER_URL}'/' -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_PASSWD}}/'${DB_PASSWD}'/' -i /home/git/gitlab/config/database.yml
|
|
|
|
# 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/.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
|
|
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
|
|
|
|
# start the nginx server
|
|
/etc/init.d/nginx start
|
|
|
|
# kickstart the rails application
|
|
wget "http://localhost" -O /dev/null
|
|
|
|
# watch the access logs
|
|
tail -F /var/log/nginx/gitlab_access.log
|