diff --git a/gitlab-ci/init.d/gitlab_ci b/gitlab-ci/init.d/gitlab_ci new file mode 100644 index 0000000..ded44e1 --- /dev/null +++ b/gitlab-ci/init.d/gitlab_ci @@ -0,0 +1,125 @@ +#! /bin/bash + +# GITLAB CI +# Maintainer: @randx +# App Version: 1.1 + +### BEGIN INIT INFO +# Provides: gitlab_ci +# 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 + + +APP_ROOT="/home/gitlab_ci/gitlab-ci" +DAEMON_OPTS="-p 3000 -d -e production" +PID_PATH="$APP_ROOT/tmp/pids" +THIN_PID="$PID_PATH/thin.pid" +RESQUE_PID="$PID_PATH/resque_worker.pid" +NAME="thin" +DESC="Gitlab CI service" + +check_pid(){ + if [ -f $THIN_PID ]; then + PID=`cat $THIN_PID` + STATUS=`ps aux | grep $PID | grep -v grep | wc -l` + else + STATUS=0 + PID=0 + fi +} + +start() { + cd $APP_ROOT + check_pid + if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then + # Program is running, exit with error code 1. + echo "Error! $DESC $NAME is currently running!" + exit 1 + else + if [ `whoami` = root ]; then + sudo -u gitlab_ci -H sh -l -c "nohup bundle exec thin start $DAEMON_OPTS > /dev/null 2>&1 &" + sudo -u gitlab_ci -H sh -l -c "mkdir -p $PID_PATH && nohup bundle exec rake environment resque:work QUEUE=runner RAILS_ENV=production PIDFILE=$RESQUE_PID > /dev/null 2>&1 &" + echo "$DESC started" + fi + fi +} + +stop() { + cd $APP_ROOT + check_pid + if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then + ## Program is running, stop it. + kill -QUIT `cat $THIN_PID` + kill -QUIT `cat $RESQUE_PID` + rm "$THIN_PID" >> /dev/null + rm "$RESQUE_PID" >> /dev/null + echo "$DESC stopped" + else + ## Program is not running, exit with error. + echo "Error! $DESC not started!" + exit 1 + fi +} + +restart() { + cd $APP_ROOT + check_pid + if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then + echo -n "Restarting $DESC: " + kill -USR2 `cat $THIN_PID` + kill -USR2 `cat $RESQUE_PID` + echo "$NAME." + else + echo "Error, $NAME not running!" + exit 1 + fi +} + +status() { + cd $APP_ROOT + check_pid + if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then + echo "$DESC with PID $PID is running." + else + echo "$DESC is not running." + exit 1 + fi +} + +## Check to see if we are running as root first. +## Found at http://www.cyberciti.biz/tips/shell-root-user-check-script.html +if [ "$(id -u)" != "0" ]; then + echo "This script must be run as root" + exit 1 +fi + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + restart + ;; + reload|force-reload) + echo -n "Reloading $DESC configuration: " + kill -HUP `cat $PID` + echo "$NAME." + ;; + status) + status + ;; + *) + echo "Usage: $NAME {start|stop|restart|reload}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/gitlab-ci/nginx/gitlab_ci b/gitlab-ci/nginx/gitlab_ci new file mode 100644 index 0000000..af7c898 --- /dev/null +++ b/gitlab-ci/nginx/gitlab_ci @@ -0,0 +1,32 @@ +# GITLAB CI +# Maintainer: @randx +# App Version: 1.1 + +upstream gitlab_ci { + server 127.0.0.1:3000; +} + +server { + listen YOUR_SERVER_IP:80 default_server; # e.g., listen 192.168.1.1:80; + server_name YOUR_SERVER_FQDN; # e.g., server_name source.example.com; + root /home/gitlab_ci/gitlab-ci/public; + + access_log /var/log/nginx/gitlab_ci_access.log; + error_log /var/log/nginx/gitlab_ci_error.log; + + location / { + try_files $uri $uri/index.html $uri.html @gitlab_ci; + } + + location @gitlab_ci { + proxy_read_timeout 300; + proxy_connect_timeout 300; + proxy_redirect off; + + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + + proxy_pass http://gitlab_ci; + } +} diff --git a/init.d/gitlab b/init.d/gitlab index c477eb2..6bf655f 100644 --- a/init.d/gitlab +++ b/init.d/gitlab @@ -2,7 +2,7 @@ # GITLAB # Maintainer: @randx -# App Version: 3.0 +# App Version: 4.0 ### BEGIN INIT INFO # Provides: gitlab diff --git a/nginx/gitlab b/nginx/gitlab index b5cb56e..d133ec9 100644 --- a/nginx/gitlab +++ b/nginx/gitlab @@ -1,6 +1,6 @@ # GITLAB # Maintainer: @randx -# App Version: 3.0 +# App Version: 4.0 upstream gitlab { server unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket;