summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rwxr-xr-xSOURCES/gitlab.init241
-rw-r--r--SPECS/gitlab.spec62
3 files changed, 216 insertions, 91 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c4fb7e4
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+SRPMS/
+SOURCES/gitlab
+SOURCES/gitlab-shell
+SOURCES/gitlab*.gz
diff --git a/SOURCES/gitlab.init b/SOURCES/gitlab.init
index a000af5..e8bb023 100755
--- a/SOURCES/gitlab.init
+++ b/SOURCES/gitlab.init
@@ -1,102 +1,203 @@
-#!/bin/bash
-#
-# GitLab
-# Contributors : @elvanja, @troyanov, @eiyaya, @foyo23, @nielsbasjes, @relip, @JasonMing, @andronat, @axilleas
-# App Version : 6.x
+#! /bin/sh
-# chkconfig: 2345 82 55
-# processname: sidekiq
-# description: Runs sidekiq for nginx integration.
+# GITLAB
+# Maintainer: @randx
+# Authors: rovanion.luckey@gmail.com, @randx
+# App Version: 6.0
-# Related (kudos @4sak3n0ne):
-# https://github.com/gitlabhq/gitlabhq/issues/1049#issuecomment-8386882
-# https://gist.github.com/3062860
+### BEGIN INIT INFO
+# Provides: gitlab
+# Required-Start: $local_fs $remote_fs $network $syslog redis-server
+# Required-Stop: $local_fs $remote_fs $network $syslog
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: GitLab git repository management
+# Description: GitLab git repository management
+### END INIT INFO
-# Save original $PATH
-# /etc/rc.d/init.d/functions resets $PATH to default(/sbin:/usr/sbin:/bin:/usr/bin).
-# Consequently, rvm and compiled ruby with custom path (which isn't /usr/bin) cannot be executed.
-ORIGINAL_PATH=$PATH
+### Environment variables
+RAILS_ENV="production"
-# Include RedHat function library
-. /etc/rc.d/init.d/functions
+# Script variable names should be lower-case not to conflict with internal
+# /bin/sh variables such as PATH, EDITOR or SHELL.
+app_root="/var/www/gitlab/gitlab"
+app_user="git"
+pid_path="$app_root/tmp/pids"
+socket_path="$app_root/tmp/sockets"
+sidekiq_pid_path="$pid_path/sidekiq.pid"
-# Restore original $PATH
-PATH=$ORIGINAL_PATH
-# The name of the service
-NAME=git
-# The username and path to the gitlab source
-USER=git
-APP_PATH=/var/www/gitlab/gitlab
+### Here ends user configuration ###
-# The PID and LOCK files used by unicorn and sidekiq
-SPID=$APP_PATH/tmp/pids/sidekiq.pid
-SLOCK=/var/lock/subsys/sidekiq
-# Ruby related path update
-export PATH="/opt/ruby-1.9.3/bin:$PATH"
+# Switch to the app_user if it is not he/she who is running the script.
+if [ "$USER" != "$app_user" ]; then
+ sudo -u "$app_user" -H -i $0 "$@"; exit;
+fi
-start() {
- cd $APP_PATH
+# Switch to the gitlab path, if it fails exit with an error.
+if ! cd "$app_root" ; then
+ echo "Failed to cd into $app_root, exiting!"; exit 1
+fi
- # Start sidekiq
- echo -n $"Starting sidekiq: "
- daemon --pidfile=$SPID --user=$USER "RAILS_ENV=production bundle exec rake sidekiq:start"
- sidekiq=$?
- [ $sidekiq -eq 0 ] && touch $SLOCK
- echo
+### Init Script functions
- return $sidekiq
+check_pids(){
+ if ! mkdir -p "$pid_path"; then
+ echo "Could not create the path $pid_path needed to store the pids."
+ exit 1
+ fi
+ if [ -f "$sidekiq_pid_path" ]; then
+ spid=$(cat "$sidekiq_pid_path")
+ else
+ spid=0
+ fi
}
-stop() {
- cd $APP_PATH
+# We use the pids in so many parts of the script it makes sense to always check them.
+# Only after start() is run should the pids change. Sidekiq sets it's own pid.
+check_pids
- # Stop sidekiq
- echo -n $"Stopping sidekiq: "
- killproc -p $SPID
- sidekiq=$?
- [ $sidekiq -eq 0 ] && rm -f $SLOCK
- echo
- return $sidekiq
+# Checks whether the different parts of the service are already running or not.
+check_status(){
+ check_pids
+ if [ $spid -ne 0 ]; then
+ kill -0 "$spid" 2>/dev/null
+ sidekiq_status="$?"
+ else
+ sidekiq_status="-1"
+ fi
}
-restart() {
- stop
- start
+# Check for stale pids and remove them if necessary
+check_stale_pids(){
+ check_status
+ # If there is a pid it is something else than 0, the service is running if
+ # *_status is == 0.
+ if [ "$spid" != "0" -a "$sidekiq_status" != "0" ]; then
+ echo "Removing stale Sidekiq web server pid. This is most likely caused by the Sidekiq crashing the last time it ran."
+ if ! rm "$sidekiq_pid_path"; then
+ echo "Unable to remove stale pid, exiting"
+ exit 1
+ fi
+ fi
+}
+
+# If no parts of the service is running, bail out.
+exit_if_not_running(){
+ check_stale_pids
+ if [ "$sidekiq_status" != "0" ]; then
+ echo "GitLab is not running."
+ exit
+ fi
+}
+
+# Starts Unicorn and Sidekiq.
+start() {
+ check_stale_pids
+
+ # If sidekiq is already running, don't start it again.
+ if [ "$sidekiq_status" = "0" ]; then
+ echo "The Sidekiq job dispatcher is already running with pid $spid, not restarting"
+ else
+ echo "Starting the GitLab Sidekiq event dispatcher..."
+ RAILS_ENV=$RAILS_ENV script/background_jobs start
+ # We are sleeping a bit here because sidekiq is slow at writing it's pid
+ sleep 2
+ fi
+
+ # Finally check the status to tell wether or not GitLab is running
+ status
+}
+
+# Asks the Unicorn and the Sidekiq if they would be so kind as to stop, if not kills them.
+stop() {
+ exit_if_not_running
+ # And do the same thing for the Sidekiq.
+ if [ "$sidekiq_status" = "0" ]; then
+ printf "Stopping Sidekiq job dispatcher."
+ RAILS_ENV=$RAILS_ENV script/background_jobs stop
+ stopping=true
+ else
+ echo "The Sidekiq was not running, must have run out of breath."
+ fi
+
+
+ # If something needs to be stopped, lets wait for it to stop. Never use SIGKILL in a script.
+ while [ "$stopping" = "true" ]; do
+ sleep 1
+ check_status
+ done
+ sleep 1
+ # Cleaning up unused pids
+ # rm "$sidekiq_pid_path" # Sidekiq seems to be cleaning up it's own pid.
+
+ status
+}
+
+# Returns the status of GitLab and it's components
+status() {
+ check_status
+ if [ "$sidekiq_status" != "0" ]; then
+ echo "GitLab is not running."
+ return
+ fi
+ if [ "$sidekiq_status" = "0" ]; then
+ echo "The GitLab Sidekiq job dispatcher with pid $spid is running."
+ else
+ printf "The GitLab Sidekiq job dispatcher is \033[31mnot running\033[0m.\n"
+ fi
+ if [ "$sidekiq_status" = "0" ]; then
+ printf "GitLab and all its components are \033[32mup and running\033[0m.\n"
+ fi
}
-get_status() {
- status -p $SPID sidekiq
+reload(){
+ exit_if_not_running
+ if [ "$wpid" = "0" ];then
+ echo "The GitLab Unicorn Web server is not running thus its configuration can't be reloaded."
+ exit 1
+ fi
+ echo "Restarting GitLab Sidekiq since it isn't capable of reloading its config..."
+ RAILS_ENV=$RAILS_ENV script/background_jobs restart
+ # Waiting 2 seconds for sidekiq to write it.
+ sleep 2
+ status
}
-query_status() {
- get_status >/dev/null 2>&1
+restart(){
+ check_status
+ if [ "$sidekiq_status" = "0" ]; then
+ stop
+ fi
+ start
}
+
+## Finally the input handling.
+
case "$1" in
start)
- query_status && exit 0
- start
- ;;
+ start
+ ;;
stop)
- query_status || exit 0
- stop
- ;;
+ stop
+ ;;
restart)
- restart
- ;;
+ restart
+ ;;
+ reload|force-reload)
+ reload
+ ;;
status)
- get_status
- ;;
+ status
+ ;;
*)
- N=/etc/init.d/$NAME
- echo "Usage: $N {start|stop|restart|status}" >&2
- exit 1
- ;;
+ echo "Usage: service gitlab {start|stop|restart|reload|status}"
+ exit 1
+ ;;
esac
-exit 0
-
+exit
diff --git a/SPECS/gitlab.spec b/SPECS/gitlab.spec
index 395f85f..7cb4f81 100644
--- a/SPECS/gitlab.spec
+++ b/SPECS/gitlab.spec
@@ -2,8 +2,8 @@
# add your specific settings here
%define app_name gitlab
-%define app_version 6.1.0
-%define gitlabshell_version 1.7.1
+%define app_version 6.2.3
+%define gitlabshell_version 1.7.6
%define ruby_version 1.9.3
# which bundle envs should not go into production?
@@ -67,22 +67,6 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%(id -un)
This is gitlab
-%pre
-# Run before the package is installed.
-# Creates the user and group which will be used to run the
-# application.
-getent group %{git_user} > /dev/null || groupadd -r %{git_user}
-getent passwd %{git_user} > /dev/null || \
- useradd -m -g %{git_user} -d %{wwwdir} -s /bin/bash \
- -c "Rails Application %{name}" %{git_user}
-getent group %{git_user} | grep -q apache || usermod -a -G %{git_user} apache
-
-test -d %{wwwdir} || mkdir -p %{wwwdir}
-chown %{git_user}.%{git_user} %{wwwdir}
-chmod 0750 %{wwwdir}
-exit 0
-
-
%prep
# prepare the source to install it during the package building
# process.
@@ -186,11 +170,35 @@ cp -p -r gitlab/{.bundle,.git*} $RPM_BUILD_ROOT/%{wwwdir}/%{name}/
touch $RPM_BUILD_ROOT/%{wwwdir}/.ssh/authorized_keys
touch $RPM_BUILD_ROOT/%{wwwdir}/gitlab-shell/gitlab-shell.log
+# enable rack-attack
+cp -p -r $RPM_BUILD_ROOT/%{wwwdir}/%{name}/config/initializers/rack_attack.rb.example $RPM_BUILD_ROOT/%{wwwdir}/%{name}/config/initializers/rack_attack.rb
+sed 's/# config.middleware.use Rack::Attack/config.middleware.use Rack::Attack/' $RPM_BUILD_ROOT/%{wwwdir}/%{name}/config/application.rb
+
# fix shebangs
grep -sHE '^#!/usr/(local/)?bin/ruby' $RPM_BUILD_ROOT/%{wwwdir}/%{name}* -r | awk -F: '{ print $1 }' | uniq | while read line; do sed -i 's@^#\!/usr/\(local/\)\?bin/ruby@#\!%{ruby_bin}@' $line; done
grep -sHE '^#!/usr/bin/env ruby' $RPM_BUILD_ROOT/%{wwwdir}/%{name}* -r | awk -F: '{ print $1 }' | uniq | while read line; do sed -i 's@^#\!/usr/bin/env ruby@#\!%{ruby_bin}@' $line; done
grep -sHE '^#!/usr/bin/env rake' $RPM_BUILD_ROOT/%{wwwdir}/%{name}* -r | awk -F: '{ print $1 }' | uniq | while read line; do sed -i 's@^#\!/usr/bin/env rake@#\!%{ruby_bindir}/rake@' $line; done
+%pre
+# Run before the package is installed.
+# Creates the user and group which will be used to run the
+# application.
+getent group %{git_user} > /dev/null || groupadd -r %{git_user}
+getent passwd %{git_user} > /dev/null || \
+ useradd -m -g %{git_user} -d %{wwwdir} -s /bin/bash \
+ -c "Rails Application %{name}" %{git_user}
+getent group %{git_user} | grep -q apache || usermod -a -G %{git_user} apache
+
+test -d %{wwwdir} || mkdir -p %{wwwdir}
+chown %{git_user}.%{git_user} %{wwwdir}
+chmod 0750 %{wwwdir}
+
+/sbin/service %{name} status > /dev/null 2>&1 && \
+ /sbin/service %{name} stop > /dev/null 2>&1
+
+exit 0
+
+
%post
# Runs after the package got installed.
# Configure here any services etc.
@@ -216,12 +224,21 @@ for selinuxvariant in %{selinux_variants}; do
done
/sbin/restorecon -R %{wwwdir}/.ssh
+if [ "$1" != "1" ] && [ -f %{wwwdir}/%{name}/config/database.yml ] && [ -f %{wwwdir}/%{name}/config/gitlab.yml ]; then
+ su %{git_user} -l -c "cd %{wwwdir}/%{name}; bundle exec rake db:migrate RAILS_ENV=production"
+ su %{git_user} -l -c "cd %{wwwdir}/%{name}; bundle exec rake assets:clean RAILS_ENV=production"
+ su %{git_user} -l -c "cd %{wwwdir}/%{name}; bundle exec rake assets:precompile RAILS_ENV=production"
+ su %{git_user} -l -c "cd %{wwwdir}/%{name}; bundle exec rake cache:clear RAILS_ENV=production"
+ /sbin/service %{name} restart > /dev/null 2>&1
+ /sbin/service httpd restart > /dev/null 2>&1
+fi
+
%preun
# Run before uninstallation
# $1 will be 1 if the package is upgraded
# and 0 if the package is deinstalled.
-if [ "$1" = 0 ] ; then
+if [ $1 -eq 0 ] ; then
/sbin/service %{name} stop > /dev/null 2>&1
/sbin/chkconfig --del %{name} || :
fi
@@ -232,14 +249,15 @@ fi
# and 0 if the package is deinstalled.
if [ $1 -eq 0 ] ; then
- userdel git
- groupdel git
+ userdel %{git_user}
+ groupdel %{git_user}
for selinuxvariant in %{selinux_variants}; do
/usr/sbin/semodule -s ${selinuxvariant} -r gitlab &> /dev/null || :
done
fi
+
%files
# describe all the files that should be included in the package
%defattr(-,root,root,)
@@ -255,6 +273,8 @@ fi
%attr(-,%{git_user},%{git_user}) %{wwwdir}/gitlab-shell/gitlab-shell.log
# run application as dedicated user
%attr(-,%{git_user},%{git_user}) %{wwwdir}/%{name}/config.ru
+# db updates need to dump the schema
+%attr(-,%{git_user},%{git_user}) %{wwwdir}/%{name}/db/schema.rb
# allow write access to special directories
%attr(0770,%{git_user},%{git_user}) %{wwwdir}/%{name}/log
%attr(0770,%{git_user},%{git_user}) %{wwwdir}/%{name}/public