diff options
-rw-r--r-- | config/puma.rb | 114 | ||||
-rw-r--r-- | config/unicorn.rb | 67 | ||||
-rw-r--r-- | lib/support/init.d/gitlab_ci | 22 |
3 files changed, 125 insertions, 78 deletions
diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000..7a7b96c --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,114 @@ +#!/usr/bin/env puma + +# Start Puma with next command: +# RAILS_ENV=production bundle exec puma -e production -C ./config/puma.rb + +application_path = '/home/gitlab_ci/gitlab-ci' + +# The directory to operate out of. +# +# The default is the current directory. +# +directory application_path + +# Set the environment in which the rack's app will run. +# +# The default is “development”. +# +environment = :production + +# Daemonize the server into the background. Highly suggest that +# this be combined with “pidfile” and “stdout_redirect”. +# +# The default is “false”. +# +daemonize true + +# Store the pid of the server in the file at “path”. +# +pidfile "#{application_path}/tmp/pids/puma.pid" + +# Use “path” as the file to store the server info state. This is +# used by “pumactl” to query and control the server. +# +state_path "#{application_path}/tmp/pids/puma.state" + +# Redirect STDOUT and STDERR to files specified. The 3rd parameter +# (“append”) specifies whether the output is appended, the default is +# “false”. +# +stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log" +# stdout_redirect '/u/apps/lolcat/log/stdout', '/u/apps/lolcat/log/stderr', true + +# Disable request logging. +# +# The default is “false”. +# +# quiet + +# Configure “min” to be the minimum number of threads to use to answer +# requests and “max” the maximum. +# +# The default is “0, 16”. +# +# threads 0, 16 + +# Bind the server to “url”. “tcp://”, “unix://” and “ssl://” are the only +# accepted protocols. +# +# The default is “tcp://0.0.0.0:9292”. +# +# bind 'tcp://0.0.0.0:9292' +bind "unix://#{application_path}/tmp/sockets/gitlab-ci.socket" + +# Instead of “bind 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'” you +# can also use the “ssl_bind” option. +# +# ssl_bind '127.0.0.1', '9292', { key: path_to_key, cert: path_to_cert } + +# Code to run before doing a restart. This code should +# close log files, database connections, etc. +# +# This can be called multiple times to add code each time. +# +# on_restart do +# puts 'On restart...' +# end + +# Command to use to restart puma. This should be just how to +# load puma itself (ie. 'ruby -Ilib bin/puma'), not the arguments +# to puma, as those are the same as the original process. +# +# restart_command '/u/app/lolcat/bin/restart_puma' + +# === Cluster mode === + +# How many worker processes to run. +# +# The default is “0”. +# +# workers 2 + +# Code to run when a worker boots to setup the process before booting +# the app. +# +# This can be called multiple times to add hooks. +# +# on_worker_boot do +# puts 'On worker boot...' +# end + +# === Puma control rack application === + +# Start the puma control rack application on “url”. This application can +# be communicated with to control the main server. Additionally, you can +# provide an authentication token, so all requests to the control server +# will need to include that token as a query parameter. This allows for +# simple authentication. +# +# Check out https://github.com/puma/puma/blob/master/lib/puma/app/status.rb +# to see what the app has available. +# +# activate_control_app 'unix:///var/run/pumactl.sock' +# activate_control_app 'unix:///var/run/pumactl.sock', { auth_token: '12345' } +# activate_control_app 'unix:///var/run/pumactl.sock', { no_token: true } diff --git a/config/unicorn.rb b/config/unicorn.rb deleted file mode 100644 index f58875a..0000000 --- a/config/unicorn.rb +++ /dev/null @@ -1,67 +0,0 @@ -# uncomment and customize to run in non-root path -# ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab-ci" - -app_dir = "/home/gitlab_ci/gitlab-ci/" -worker_processes 2 -working_directory app_dir - -# Load app into the master before forking workers for super-fast -# worker spawn times -preload_app true - -# nuke workers after 30 seconds (60 is the default) -timeout 30 - -# listen on a Unix domain socket and/or a TCP port, - -#listen 8080 # listen to port 8080 on all TCP interfaces -#listen "127.0.0.1:8080" # listen to port 8080 on the loopback interface -listen "#{app_dir}/tmp/sockets/gitlab-ci.socket" - -pid "#{app_dir}/tmp/pids/unicorn.pid" -stderr_path "#{app_dir}/log/unicorn.stderr.log" -stdout_path "#{app_dir}/log/unicorn.stdout.log" - -# http://www.rubyenterpriseedition.com/faq.html#adapt_apps_for_cow -if GC.respond_to?(:copy_on_write_friendly=) - GC.copy_on_write_friendly = true -end - - -before_fork do |server, worker| - # the following is highly recomended for Rails + "preload_app true" - # as there's no need for the master process to hold a connection - defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! - - ## - # When sent a USR2, Unicorn will suffix its pidfile with .oldbin and - # immediately start loading up a new version of itself (loaded with a new - # version of our app). When this new Unicorn is completely loaded - # it will begin spawning workers. The first worker spawned will check to - # see if an .oldbin pidfile exists. If so, this means we've just booted up - # a new Unicorn and need to tell the old one that it can now die. To do so - # we send it a QUIT. - # - # Using this method we get 0 downtime deploys. - - old_pid = "#{server.config[:pid]}.oldbin" - - if File.exists?(old_pid) && server.pid != old_pid - begin - sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU - Process.kill(sig, File.read(old_pid).to_i) - rescue Errno::ENOENT, Errno::ESRCH - # someone else did our job for us - end - end -end - -after_fork do |server, worker| - # Unicorn master loads the app then forks off workers - because of the way - # Unix forking works, we need to make sure we aren't using any of the parent's - # sockets, e.g. db connection - - defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection - # Redis and Memcached would go here but their connections are established - # on demand, so the master never opens a socket -end diff --git a/lib/support/init.d/gitlab_ci b/lib/support/init.d/gitlab_ci index 57d498c..30c9787 100644 --- a/lib/support/init.d/gitlab_ci +++ b/lib/support/init.d/gitlab_ci @@ -2,7 +2,7 @@ # GITLAB CI # Maintainer: @randx -# App Version: 2.0 +# App Version: 2.2 ### BEGIN INIT INFO # Provides: gitlab-ci @@ -16,18 +16,18 @@ APP_ROOT="/home/gitlab_ci/gitlab-ci" -DAEMON_OPTS="-c $APP_ROOT/config/unicorn.rb -E production" +DAEMON_OPTS="-C $APP_ROOT/config/puma.rb -e production" PID_PATH="$APP_ROOT/tmp/pids" -UNICORN_PID="$PID_PATH/unicorn.pid" +WEB_SERVER_PID="$PID_PATH/puma.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" +NAME="GitLab CI" DESC="Gitlab CI service" check_pid(){ - if [ -f $UNICORN_PID ]; then - PID=`cat $UNICORN_PID` + if [ -f $WEB_SERVER_PID ]; then + PID=`cat $WEB_SERVER_PID` SPID=`cat $SIDEKIQ_PID` STATUS=`ps aux | grep $PID | grep -v grep | wc -l` else @@ -41,11 +41,11 @@ start() { 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!" + echo "Error! $DESC 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 "RAILS_ENV=production bundle exec puma $DAEMON_OPTS" sudo -u gitlab_ci -H bash -l -c "mkdir -p $PID_PATH && $START_SIDEKIQ > /dev/null 2>&1 &" echo "$DESC started" fi @@ -57,9 +57,9 @@ stop() { check_pid if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then ## Program is running, stop it. - kill -QUIT `cat $UNICORN_PID` + kill -QUIT `cat $WEB_SERVER_PID` sudo -u gitlab_ci -H bash -l -c "mkdir -p $PID_PATH && $STOP_SIDEKIQ > /dev/null 2>&1 &" - rm "$UNICORN_PID" >> /dev/null + rm "$WEB_SERVER_PID" >> /dev/null echo "$DESC stopped" else ## Program is not running, exit with error. @@ -73,7 +73,7 @@ restart() { check_pid if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then echo "Restarting $DESC..." - kill -USR2 `cat $UNICORN_PID` + kill -USR2 `cat $WEB_SERVER_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 &" |