Commit 2c0f4c766458b15771b6a7b64760c9cb37b8ccfe
Exists in
master
and in
4 other branches
Merge branch 'unicorn_rake_tasks' of /home/git/repositories/gitlab/gitlabhq
Showing
4 changed files
with
118 additions
and
27 deletions
Show diff stats
lib/support/init.d/gitlab
| @@ -22,7 +22,6 @@ RAILS_ENV="production" | @@ -22,7 +22,6 @@ RAILS_ENV="production" | ||
| 22 | # /bin/sh variables such as PATH, EDITOR or SHELL. | 22 | # /bin/sh variables such as PATH, EDITOR or SHELL. |
| 23 | app_root="/home/git/gitlab" | 23 | app_root="/home/git/gitlab" |
| 24 | app_user="git" | 24 | app_user="git" |
| 25 | -unicorn_conf="$app_root/config/unicorn.rb" | ||
| 26 | pid_path="$app_root/tmp/pids" | 25 | pid_path="$app_root/tmp/pids" |
| 27 | socket_path="$app_root/tmp/sockets" | 26 | socket_path="$app_root/tmp/sockets" |
| 28 | web_server_pid_path="$pid_path/unicorn.pid" | 27 | web_server_pid_path="$pid_path/unicorn.pid" |
| @@ -129,7 +128,7 @@ start() { | @@ -129,7 +128,7 @@ start() { | ||
| 129 | # Remove old socket if it exists | 128 | # Remove old socket if it exists |
| 130 | rm -f "$socket_path"/gitlab.socket 2>/dev/null | 129 | rm -f "$socket_path"/gitlab.socket 2>/dev/null |
| 131 | # Start the webserver | 130 | # Start the webserver |
| 132 | - bundle exec unicorn_rails -D -c "$unicorn_conf" -E "$RAILS_ENV" | 131 | + RAILS_ENV=$RAILS_ENV script/web start |
| 133 | fi | 132 | fi |
| 134 | 133 | ||
| 135 | # If sidekiq is already running, don't start it again. | 134 | # If sidekiq is already running, don't start it again. |
| @@ -137,7 +136,7 @@ start() { | @@ -137,7 +136,7 @@ start() { | ||
| 137 | echo "The Sidekiq job dispatcher is already running with pid $spid, not restarting" | 136 | echo "The Sidekiq job dispatcher is already running with pid $spid, not restarting" |
| 138 | else | 137 | else |
| 139 | echo "Starting the GitLab Sidekiq event dispatcher..." | 138 | echo "Starting the GitLab Sidekiq event dispatcher..." |
| 140 | - RAILS_ENV=$RAILS_ENV bundle exec rake sidekiq:start | 139 | + RAILS_ENV=$RAILS_ENV script/background_jobs start |
| 141 | # We are sleeping a bit here because sidekiq is slow at writing it's pid | 140 | # We are sleeping a bit here because sidekiq is slow at writing it's pid |
| 142 | sleep 2 | 141 | sleep 2 |
| 143 | fi | 142 | fi |
| @@ -151,7 +150,7 @@ stop() { | @@ -151,7 +150,7 @@ stop() { | ||
| 151 | exit_if_not_running | 150 | exit_if_not_running |
| 152 | # If the Unicorn web server is running, tell it to stop; | 151 | # If the Unicorn web server is running, tell it to stop; |
| 153 | if [ "$web_status" = "0" ]; then | 152 | if [ "$web_status" = "0" ]; then |
| 154 | - kill -QUIT "$wpid" | 153 | + RAILS_ENV=$RAILS_ENV script/web stop |
| 155 | echo "Stopping the GitLab Unicorn web server..." | 154 | echo "Stopping the GitLab Unicorn web server..." |
| 156 | stopping=true | 155 | stopping=true |
| 157 | else | 156 | else |
| @@ -160,7 +159,7 @@ stop() { | @@ -160,7 +159,7 @@ stop() { | ||
| 160 | # And do the same thing for the Sidekiq. | 159 | # And do the same thing for the Sidekiq. |
| 161 | if [ "$sidekiq_status" = "0" ]; then | 160 | if [ "$sidekiq_status" = "0" ]; then |
| 162 | printf "Stopping Sidekiq job dispatcher." | 161 | printf "Stopping Sidekiq job dispatcher." |
| 163 | - RAILS_ENV=$RAILS_ENV bundle exec rake sidekiq:stop | 162 | + RAILS_ENV=$RAILS_ENV script/background_jobs stop |
| 164 | stopping=true | 163 | stopping=true |
| 165 | else | 164 | else |
| 166 | echo "The Sidekiq was not running, must have run out of breath." | 165 | echo "The Sidekiq was not running, must have run out of breath." |
| @@ -215,10 +214,10 @@ reload(){ | @@ -215,10 +214,10 @@ reload(){ | ||
| 215 | exit 1 | 214 | exit 1 |
| 216 | fi | 215 | fi |
| 217 | printf "Reloading GitLab Unicorn configuration... " | 216 | printf "Reloading GitLab Unicorn configuration... " |
| 218 | - kill -USR2 "$wpid" | 217 | + RAILS_ENV=$RAILS_ENV script/web reload |
| 219 | echo "Done." | 218 | echo "Done." |
| 220 | echo "Restarting GitLab Sidekiq since it isn't capable of reloading its config..." | 219 | echo "Restarting GitLab Sidekiq since it isn't capable of reloading its config..." |
| 221 | - RAILS_ENV=$RAILS_ENV bundle exec rake sidekiq:restart | 220 | + RAILS_ENV=$RAILS_ENV script/background_jobs restart |
| 222 | # Waiting 2 seconds for sidekiq to write it. | 221 | # Waiting 2 seconds for sidekiq to write it. |
| 223 | sleep 2 | 222 | sleep 2 |
| 224 | status | 223 | status |
lib/tasks/sidekiq.rake
| 1 | namespace :sidekiq do | 1 | namespace :sidekiq do |
| 2 | desc "GITLAB | Stop sidekiq" | 2 | desc "GITLAB | Stop sidekiq" |
| 3 | task :stop do | 3 | task :stop do |
| 4 | - system "bundle exec sidekiqctl stop #{pidfile}" | 4 | + system "script/background_jobs stop" |
| 5 | end | 5 | end |
| 6 | 6 | ||
| 7 | - desc "GITLAB | Start sidekiq" | ||
| 8 | - task :start => :restart | 7 | + desc "GITLAB | Start sidekiq" do |
| 8 | + system "script/background_jobs start" | ||
| 9 | + end | ||
| 9 | 10 | ||
| 10 | - desc 'GitLab | Restart sidekiq' | ||
| 11 | - task :restart do | ||
| 12 | - if File.exist?(pidfile) | ||
| 13 | - puts 'Shutting down existing sidekiq process.' | ||
| 14 | - Rake::Task['sidekiq:stop'].invoke | ||
| 15 | - puts 'Starting new sidekiq process.' | ||
| 16 | - end | ||
| 17 | - system "bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,gitlab_shell,common,default -e #{Rails.env} -P #{pidfile} -d -L #{log_file} >> #{log_file} 2>&1" | 11 | + desc 'GitLab | Restart sidekiq' do |
| 12 | + system "script/background_jobs restart" | ||
| 18 | end | 13 | end |
| 19 | 14 | ||
| 20 | desc "GITLAB | Start sidekiq with launchd on Mac OS X" | 15 | desc "GITLAB | Start sidekiq with launchd on Mac OS X" |
| 21 | task :launchd do | 16 | task :launchd do |
| 22 | - system "bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,gitlab_shell,common,default -e #{Rails.env} -P #{pidfile} >> #{log_file} 2>&1" | ||
| 23 | - end | ||
| 24 | - | ||
| 25 | - def pidfile | ||
| 26 | - Rails.root.join("tmp", "pids", "sidekiq.pid") | ||
| 27 | - end | ||
| 28 | - | ||
| 29 | - def log_file | ||
| 30 | - Rails.root.join("log", "sidekiq.log") | 17 | + system "script/background_jobs start_no_deamonize" |
| 31 | end | 18 | end |
| 32 | end | 19 | end |
| @@ -0,0 +1,56 @@ | @@ -0,0 +1,56 @@ | ||
| 1 | +#!/bin/bash | ||
| 2 | + | ||
| 3 | +cd $(dirname $0)/.. | ||
| 4 | +app_root=$(pwd) | ||
| 5 | +sidekiq_pidfile="$app_root/tmp/pids/sidekiq.pid" | ||
| 6 | +sidekiq_logfile="$app_root/log/sidekiq.log" | ||
| 7 | +gitlab_user=$(ls -l config.ru | awk '{print $3}') | ||
| 8 | + | ||
| 9 | +function stop | ||
| 10 | +{ | ||
| 11 | + bundle exec sidekiqctl stop $sidekiq_pidfile &>> $sidekiq_logfile | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +function killall | ||
| 15 | +{ | ||
| 16 | + pkill -u $gitlab_user -f sidekiq | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +function restart | ||
| 20 | +{ | ||
| 21 | + if [ -f $sidekiq_pidfile ]; then | ||
| 22 | + stop | ||
| 23 | + fi | ||
| 24 | + killall | ||
| 25 | + start_sidekiq -d -L $sidekiq_logfile | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +function start_no_deamonize | ||
| 29 | +{ | ||
| 30 | + start_sidekiq | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +function start_sidekiq | ||
| 34 | +{ | ||
| 35 | + bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,gitlab_shell,common,default -e $RAILS_ENV -P $sidekiq_pidfile $@ &>> $sidekiq_logfile | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +case "$1" in | ||
| 39 | + stop) | ||
| 40 | + stop | ||
| 41 | + ;; | ||
| 42 | + start) | ||
| 43 | + restart | ||
| 44 | + ;; | ||
| 45 | + start_no_deamonize) | ||
| 46 | + start_no_deamonize | ||
| 47 | + ;; | ||
| 48 | + restart) | ||
| 49 | + restart | ||
| 50 | + ;; | ||
| 51 | + killall) | ||
| 52 | + killall | ||
| 53 | + ;; | ||
| 54 | + *) | ||
| 55 | + echo "Usage: RAILS_ENV=your_env $0 {stop|start|start_no_deamonize|restart|killall}" | ||
| 56 | +esac |
| @@ -0,0 +1,49 @@ | @@ -0,0 +1,49 @@ | ||
| 1 | +#!/bin/bash | ||
| 2 | + | ||
| 3 | +cd $(dirname $0)/.. | ||
| 4 | +app_root=$(pwd) | ||
| 5 | + | ||
| 6 | +unicorn_pidfile="$app_root/tmp/pids/unicorn.pid" | ||
| 7 | +unicorn_config="$app_root/config/unicorn.rb" | ||
| 8 | + | ||
| 9 | +function get_unicorn_pid | ||
| 10 | +{ | ||
| 11 | + local pid=$(cat $unicorn_pidfile) | ||
| 12 | + if [ -z $pid ] ; then | ||
| 13 | + echo "Could not find a PID in $unicorn_pidfile" | ||
| 14 | + exit 1 | ||
| 15 | + fi | ||
| 16 | + unicorn_pid=$pid | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +function start | ||
| 20 | +{ | ||
| 21 | + bundle exec unicorn_rails -D -c $unicorn_config -E $RAILS_ENV | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +function stop | ||
| 25 | +{ | ||
| 26 | + get_unicorn_pid | ||
| 27 | + kill -QUIT $unicorn_pid | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +function reload | ||
| 31 | +{ | ||
| 32 | + get_unicorn_pid | ||
| 33 | + kill -USR2 $unicorn_pid | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +case "$1" in | ||
| 37 | + start) | ||
| 38 | + start | ||
| 39 | + ;; | ||
| 40 | + stop) | ||
| 41 | + stop | ||
| 42 | + ;; | ||
| 43 | + reload) | ||
| 44 | + reload | ||
| 45 | + ;; | ||
| 46 | + *) | ||
| 47 | + echo "Usage: RAILS_ENV=your_env $0 {start|stop|reload}" | ||
| 48 | + ;; | ||
| 49 | +esac |