Skip to content

Commit fcd87ac

Browse files
committed
Add puma relevant files
1 parent a334104 commit fcd87ac

File tree

4 files changed

+246
-0
lines changed

4 files changed

+246
-0
lines changed

app-server/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Alternative configuration file for the `puma` application server. Copy it under `/home/git/gitlab/config/` and rename it to `puma.rb`.

app-server/puma.rb

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env puma
2+
3+
# Start Puma with next command:
4+
# RAILS_ENV=production bundle exec puma -C ./config/puma.rb
5+
6+
# uncomment and customize to run in non-root path
7+
# note that config/gitlab.yml web path should also be changed
8+
# ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"
9+
10+
application_path = '/home/git/gitlab'
11+
directory application_path
12+
environment 'production'
13+
daemonize true
14+
pidfile "#{application_path}/tmp/pids/puma.pid"
15+
state_path "#{application_path}/tmp/pids/puma.state"
16+
stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log"
17+
18+
# Configure “min” to be the minimum number of threads to use to answer
19+
# requests and “max” the maximum.
20+
#
21+
# The default is “0, 16”.
22+
#
23+
# threads 0, 16
24+
25+
# Bind the server to “url”. “tcp://”, “unix://” and “ssl://” are the only
26+
# accepted protocols.
27+
#
28+
#
29+
# The default is “tcp://0.0.0.0:9292”.
30+
#
31+
# bind 'tcp://0.0.0.0:9292'
32+
# bind 'unix:///var/run/puma.sock'
33+
# bind 'unix:///var/run/puma.sock?umask=0777'
34+
# bind 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
35+
#
36+
## Comment the next line if you use apache.
37+
bind "unix://#{application_path}/tmp/sockets/gitlab.socket"
38+
39+
# Instead of “bind 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'” you
40+
# can also use the “ssl_bind” option.
41+
#
42+
# ssl_bind '127.0.0.1', '9292', { key: path_to_key, cert: path_to_cert }
43+
44+
# Code to run before doing a restart. This code should
45+
# close log files, database connections, etc.
46+
#
47+
# This can be called multiple times to add code each time.
48+
#
49+
# on_restart do
50+
# puts 'On restart...'
51+
# end
52+
53+
# Command to use to restart puma. This should be just how to
54+
# load puma itself (ie. 'ruby -Ilib bin/puma'), not the arguments
55+
# to puma, as those are the same as the original process.
56+
#
57+
# restart_command '/u/app/lolcat/bin/restart_puma'
58+
59+
# === Cluster mode ===
60+
61+
# How many worker processes to run.
62+
#
63+
# The default is “0”.
64+
#
65+
# workers 2
66+
67+
# GitLab cluster mode recommendations
68+
# If you have more than 1 GB RAM, uncomment one of the following lines:
69+
#
70+
# workers 2 # if you have at least 1.5 GB RAM
71+
# workers 3 # if you have at least 2 GB RAM
72+
# workers 4 # if you have at least 2.5 GB RAM
73+
74+
# Code to run when a worker boots to setup the process before booting
75+
# the app.
76+
#
77+
# This can be called multiple times to add hooks.
78+
#
79+
# on_worker_boot do
80+
# puts 'On worker boot...'
81+
# end
82+
83+
# === Puma control rack application ===
84+
85+
# Start the puma control rack application on “url”. This application can
86+
# be communicated with to control the main server. Additionally, you can
87+
# provide an authentication token, so all requests to the control server
88+
# will need to include that token as a query parameter. This allows for
89+
# simple authentication.
90+
#
91+
# Check out https://github.com/puma/puma/blob/master/lib/puma/app/status.rb
92+
# to see what the app has available.
93+
#
94+
# activate_control_app 'unix:///var/run/pumactl.sock'
95+
# activate_control_app 'unix:///var/run/pumactl.sock', { auth_token: '12345' }
96+
# activate_control_app 'unix:///var/run/pumactl.sock', { no_token: true }

init/sysvinit/debian/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Alternative sysvinit file for puma. Tested on Debian/Ubuntu but this should work for all Debian based distros. Make sure you have the `puma` gem installed and `puma.rb` in `/home/git/gitlab/config/`.
2+
3+
Get `gitlab-puma` in your `/etc/init.d/` directory:
4+
5+
wget -O /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/init/sysvinit/debian/gitlab-puma
6+
7+
Then start the service with:
8+
9+
service gitlab start

init/sysvinit/debian/gitlab-puma

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#! /bin/bash
2+
3+
# GITLAB
4+
# Maintainer: @randx
5+
# App Version: 5.2
6+
7+
### BEGIN INIT INFO
8+
# Provides: gitlab
9+
# Required-Start: $local_fs $remote_fs $network $syslog redis-server
10+
# Required-Stop: $local_fs $remote_fs $network $syslog
11+
# Default-Start: 2 3 4 5
12+
# Default-Stop: 0 1 6
13+
# Short-Description: GitLab git repository management
14+
# Description: GitLab git repository management
15+
### END INIT INFO
16+
17+
18+
APP_ROOT="/home/git/gitlab"
19+
APP_USER="git"
20+
DAEMON_OPTS="-C $APP_ROOT/config/puma.rb"
21+
PID_PATH="$APP_ROOT/tmp/pids"
22+
SOCKET_PATH="$APP_ROOT/tmp/sockets"
23+
SOCKET_FILE="$SOCKET_PATH/gitlab.socket"
24+
WEB_SERVER_PID="$PID_PATH/puma.pid"
25+
SIDEKIQ_PID="$PID_PATH/sidekiq.pid"
26+
STOP_SIDEKIQ="RAILS_ENV=production bundle exec rake sidekiq:stop"
27+
START_SIDEKIQ="RAILS_ENV=production bundle exec rake sidekiq:start"
28+
NAME="gitlab"
29+
DESC="GitLab service"
30+
31+
check_pid(){
32+
if [ -f $WEB_SERVER_PID ]; then
33+
PID=`cat $WEB_SERVER_PID`
34+
SPID=`cat $SIDEKIQ_PID`
35+
STATUS=`ps aux | grep $PID | grep -v grep | wc -l`
36+
else
37+
STATUS=0
38+
PID=0
39+
fi
40+
}
41+
42+
execute() {
43+
sudo -u $APP_USER -H bash -l -c "$1"
44+
}
45+
46+
start() {
47+
cd $APP_ROOT
48+
check_pid
49+
if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then
50+
# Program is running, exit with error code 1.
51+
echo "Error! $DESC $NAME is currently running!"
52+
exit 1
53+
else
54+
if [ `whoami` = root ]; then
55+
! [ -e $SOCKET_FILE ] || execute "rm $SOCKET_FILE"
56+
execute "RAILS_ENV=production bundle exec puma $DAEMON_OPTS"
57+
execute "mkdir -p $PID_PATH && $START_SIDEKIQ > /dev/null 2>&1 &"
58+
echo "$DESC started"
59+
fi
60+
fi
61+
}
62+
63+
stop() {
64+
cd $APP_ROOT
65+
check_pid
66+
if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then
67+
## Program is running, stop it.
68+
kill -QUIT `cat $WEB_SERVER_PID`
69+
! [ -e $SOCKET_FILE ] || execute "rm $SOCKET_FILE"
70+
execute "mkdir -p $PID_PATH && $STOP_SIDEKIQ > /dev/null 2>&1 &"
71+
rm "$WEB_SERVER_PID" >> /dev/null
72+
echo "$DESC stopped"
73+
else
74+
## Program is not running, exit with error.
75+
echo "Error! $DESC is not started!"
76+
exit 1
77+
fi
78+
}
79+
80+
restart() {
81+
cd $APP_ROOT
82+
check_pid
83+
if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then
84+
echo "Restarting $DESC..."
85+
kill -USR2 `cat $WEB_SERVER_PID`
86+
execute "mkdir -p $PID_PATH && $STOP_SIDEKIQ > /dev/null 2>&1"
87+
if [ `whoami` = root ]; then
88+
execute "mkdir -p $PID_PATH && $START_SIDEKIQ > /dev/null 2>&1 &"
89+
fi
90+
echo "$DESC restarted."
91+
else
92+
echo "Error, $NAME not running!"
93+
exit 1
94+
fi
95+
}
96+
97+
status() {
98+
cd $APP_ROOT
99+
check_pid
100+
if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then
101+
echo "$DESC / Puma with PID $PID is running."
102+
echo "$DESC / Sidekiq with PID $SPID is running."
103+
else
104+
echo "$DESC is not running."
105+
exit 1
106+
fi
107+
}
108+
109+
## Check to see if we are running as root first.
110+
## Found at http://www.cyberciti.biz/tips/shell-root-user-check-script.html
111+
if [ "$(id -u)" != "0" ]; then
112+
echo "This script must be run as root"
113+
exit 1
114+
fi
115+
116+
case "$1" in
117+
start)
118+
start
119+
;;
120+
stop)
121+
stop
122+
;;
123+
restart)
124+
restart
125+
;;
126+
reload|force-reload)
127+
echo -n "Reloading $NAME configuration: "
128+
kill -HUP `cat $PID`
129+
echo "done."
130+
;;
131+
status)
132+
status
133+
;;
134+
*)
135+
echo "Usage: sudo service gitlab {start|stop|restart|reload}" >&2
136+
exit 1
137+
;;
138+
esac
139+
140+
exit 0

0 commit comments

Comments
 (0)