summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-01-16 16:04:41 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-01-16 16:04:41 +0200
commit198d13e472b3ebdf8707c12229bc9d4f97272b0c (patch)
tree5045bea95728423c5faa4d8719a5221f72fef5bc
parentf4c8edc91654a836b2de87bae785fcab70c36fdb (diff)
downloadgitlab-ci-198d13e472b3ebdf8707c12229bc9d4f97272b0c.tar.gz
support scripts
-rw-r--r--doc/installation.md4
-rw-r--r--lib/support/init.d/gitlab_ci131
-rw-r--r--lib/support/nginx/gitlab_ci32
3 files changed, 165 insertions, 2 deletions
diff --git a/doc/installation.md b/doc/installation.md
index 7cd458d..25a8b54 100644
--- a/doc/installation.md
+++ b/doc/installation.md
@@ -76,7 +76,7 @@ Create a user for GitLab:
Download the init script (will be /etc/init.d/gitlab_ci):
- sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/gitlab-ci/init.d/gitlab_ci -P /etc/init.d/
+ sudo wget https://raw.github.com/gitlabhq/gitlab-ci/master/lib/support/init.d/gitlab_ci -P /etc/init.d/
sudo chmod +x /etc/init.d/gitlab_ci
Make GitLab start on boot:
@@ -101,7 +101,7 @@ Start your GitLab instance:
Download an example site config:
- sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/gitlab-ci/nginx/gitlab_ci -P /etc/nginx/sites-available/
+ sudo wget https://raw.github.com/gitlabhq/gitlab-ci/master/lib/support/nginx/gitlab_ci -P /etc/nginx/sites-available/
sudo ln -s /etc/nginx/sites-available/gitlab_ci /etc/nginx/sites-enabled/gitlab_ci
Make sure to edit the config file to match your setup:
diff --git a/lib/support/init.d/gitlab_ci b/lib/support/init.d/gitlab_ci
new file mode 100644
index 0000000..57d498c
--- /dev/null
+++ b/lib/support/init.d/gitlab_ci
@@ -0,0 +1,131 @@
+#! /bin/bash
+
+# GITLAB CI
+# Maintainer: @randx
+# App Version: 2.0
+
+### 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 CI
+# Description: GitLab CI
+### END INIT INFO
+
+
+APP_ROOT="/home/gitlab_ci/gitlab-ci"
+DAEMON_OPTS="-c $APP_ROOT/config/unicorn.rb -E production"
+PID_PATH="$APP_ROOT/tmp/pids"
+UNICORN_PID="$PID_PATH/unicorn.pid"
+SIDEKIQ_PID="$PID_PATH/sidekiq.pid"
+STOP_SIDEKIQ="RAILS_ENV=production bundle exec rake sidekiq:stop"
+START_SIDEKIQ="RAILS_ENV=production bundle exec rake sidekiq:start"
+NAME="unicorn"
+DESC="Gitlab CI service"
+
+check_pid(){
+ if [ -f $UNICORN_PID ]; then
+ PID=`cat $UNICORN_PID`
+ SPID=`cat $SIDEKIQ_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 bash -l -c "nohup bundle exec unicorn_rails $DAEMON_OPTS > /dev/null 2>&1 &"
+ sudo -u gitlab_ci -H bash -l -c "mkdir -p $PID_PATH && $START_SIDEKIQ > /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 $UNICORN_PID`
+ sudo -u gitlab_ci -H bash -l -c "mkdir -p $PID_PATH && $STOP_SIDEKIQ > /dev/null 2>&1 &"
+ rm "$UNICORN_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 "Restarting $DESC..."
+ kill -USR2 `cat $UNICORN_PID`
+ sudo -u gitlab_ci -H bash -l -c "mkdir -p $PID_PATH && $STOP_SIDEKIQ > /dev/null 2>&1 &"
+ if [ `whoami` = root ]; then
+ sudo -u gitlab_ci -H bash -l -c "mkdir -p $PID_PATH && $START_SIDEKIQ > /dev/null 2>&1 &"
+ fi
+ echo "$DESC restarted."
+ 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 / Unicorn with PID $PID is running."
+ echo "$DESC / Sidekiq with PID $SPID 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 $NAME configuration: "
+ kill -HUP `cat $PID`
+ echo "done."
+ ;;
+ status)
+ status
+ ;;
+ *)
+ echo "Usage: sudo service gitlab {start|stop|restart|reload}" >&2
+ exit 1
+ ;;
+esac
+
+exit 0
diff --git a/lib/support/nginx/gitlab_ci b/lib/support/nginx/gitlab_ci
new file mode 100644
index 0000000..7c5fca1
--- /dev/null
+++ b/lib/support/nginx/gitlab_ci
@@ -0,0 +1,32 @@
+# GITLAB CI
+# Maintainer: @randx
+# App Version: 2.0
+
+upstream gitlab_ci {
+ server unix:/home/gitlab_ci/gitlab-ci/tmp/sockets/gitlab-ci.socket;
+}
+
+server {
+ listen 80 default_server; # e.g., listen 192.168.1.1:80;
+ server_name ci.gitlab.org; # 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;
+ }
+} \ No newline at end of file