capistrano-puma-a 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ namespace :load do
2
+ task :defaults do
3
+ # Nginx and puma configuration
4
+ set :nginx_config_name, -> { "#{fetch(:application)}_#{fetch(:stage)}" }
5
+ set :nginx_sites_available_path, -> { '/etc/nginx/sites-available' }
6
+ set :nginx_sites_enabled_path, -> { '/etc/nginx/sites-enabled' }
7
+ set :nginx_server_name, -> { "localhost #{fetch(:application)}.local" }
8
+ set :nginx_flags, -> { 'fail_timeout=0' }
9
+ set :nginx_http_flags, -> { fetch(:nginx_flags) }
10
+ set :nginx_socket_flags, -> { fetch(:nginx_flags) }
11
+ set :nginx_use_ssl, false
12
+ end
13
+ end
14
+ namespace :puma do
15
+ desc 'Setup nginx configuration'
16
+ task :nginx_config do
17
+ on roles(fetch(:puma_nginx, :web)) do |role|
18
+ puma_switch_user(role) do
19
+ template_puma('nginx_conf', "/tmp/nginx_#{fetch(:nginx_config_name)}", role)
20
+ sudo :mv, "/tmp/nginx_#{fetch(:nginx_config_name)} #{fetch(:nginx_sites_available_path)}/#{fetch(:nginx_config_name)}"
21
+ sudo :ln, '-fs', "#{fetch(:nginx_sites_available_path)}/#{fetch(:nginx_config_name)} #{fetch(:nginx_sites_enabled_path)}/#{fetch(:nginx_config_name)}"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,197 @@
1
+ namespace :load do
2
+ task :defaults do
3
+ set :puma_default_hooks, -> { true }
4
+ set :puma_role, :app
5
+ set :puma_env, -> { fetch(:rack_env, fetch(:rails_env, fetch(:stage))) }
6
+ # Configure "min" to be the minimum number of threads to use to answer
7
+ # requests and "max" the maximum.
8
+ set :puma_threads, [0, 16]
9
+ set :puma_workers, 0
10
+ set :puma_rackup, -> { File.join(current_path, 'config.ru') }
11
+ set :puma_state, -> { File.join(shared_path, 'tmp', 'pids', 'puma.state') }
12
+ set :puma_pid, -> { File.join(shared_path, 'tmp', 'pids', 'puma.pid') }
13
+ set :puma_bind, -> { File.join("unix://#{shared_path}", 'tmp', 'sockets', 'puma.sock') }
14
+ set :puma_default_control_app, -> { File.join("unix://#{shared_path}", 'tmp', 'sockets', 'pumactl.sock') }
15
+ set :puma_conf, -> { File.join(shared_path, 'puma.rb') }
16
+ set :puma_access_log, -> { File.join(shared_path, 'log', 'puma_access.log') }
17
+ set :puma_error_log, -> { File.join(shared_path, 'log', 'puma_error.log') }
18
+ set :puma_init_active_record, false
19
+ set :puma_preload_app, false
20
+
21
+ # Chruby, Rbenv and RVM integration
22
+ append :chruby_map_bins, 'puma', 'pumactl'
23
+ append :rbenv_map_bins, 'puma', 'pumactl'
24
+ append :rvm_map_bins, 'puma', 'pumactl'
25
+
26
+ # Bundler integration
27
+ append :bundle_bins, 'puma', 'pumactl'
28
+ end
29
+ end
30
+
31
+ namespace :deploy do
32
+ before :starting, :check_puma_hooks do
33
+ invoke 'puma:add_default_hooks' if fetch(:puma_default_hooks)
34
+ end
35
+ end
36
+
37
+ namespace :puma do
38
+
39
+ desc 'Setup Puma config file'
40
+ task :config do
41
+ on roles(fetch(:puma_role)) do |role|
42
+ template_puma 'puma', fetch(:puma_conf), role
43
+ end
44
+ end
45
+
46
+ desc 'Start puma'
47
+ task :start do
48
+ on roles (fetch(:puma_role)) do |role|
49
+ puma_switch_user(role) do
50
+ if test "[ -f #{fetch(:puma_conf)} ]"
51
+ info "using conf file #{fetch(:puma_conf)}"
52
+ else
53
+ invoke 'puma:config'
54
+ end
55
+ within current_path do
56
+ with rack_env: fetch(:puma_env) do
57
+ execute :puma, "-C #{fetch(:puma_conf)} --daemon"
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ %w[halt stop status].map do |command|
65
+ desc "#{command} puma"
66
+ task command do
67
+ on roles (fetch(:puma_role)) do |role|
68
+ within current_path do
69
+ puma_switch_user(role) do
70
+ with rack_env: fetch(:puma_env) do
71
+ if test "[ -f #{fetch(:puma_pid)} ]"
72
+ if test :kill, "-0 $( cat #{fetch(:puma_pid)} )"
73
+ execute :pumactl, "-S #{fetch(:puma_state)} -F #{fetch(:puma_conf)} #{command}"
74
+ else
75
+ # delete invalid pid file , process is not running.
76
+ execute :rm, fetch(:puma_pid)
77
+ end
78
+ else
79
+ #pid file not found, so puma is probably not running or it using another pidfile
80
+ warn 'Puma not running'
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ %w[phased-restart restart].map do |command|
90
+ desc "#{command} puma"
91
+ task command do
92
+ on roles (fetch(:puma_role)) do |role|
93
+ within current_path do
94
+ puma_switch_user(role) do
95
+ with rack_env: fetch(:puma_env) do
96
+ if test "[ -f #{fetch(:puma_pid)} ]" and test :kill, "-0 $( cat #{fetch(:puma_pid)} )"
97
+ # NOTE pid exist but state file is nonsense, so ignore that case
98
+ execute :pumactl, "-S #{fetch(:puma_state)} -F #{fetch(:puma_conf)} #{command}"
99
+ else
100
+ # Puma is not running or state file is not present : Run it
101
+ invoke 'puma:start'
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+
110
+ task :check do
111
+ on roles (fetch(:puma_role)) do |role|
112
+ #Create puma.rb for new deployments
113
+ unless test "[ -f #{fetch(:puma_conf)} ]"
114
+ warn 'puma.rb NOT FOUND!'
115
+ #TODO DRY
116
+ template_puma 'puma', fetch(:puma_conf), role
117
+ info 'puma.rb generated'
118
+ end
119
+ end
120
+ end
121
+
122
+
123
+ task :smart_restart do
124
+ if !puma_preload_app? && puma_workers.to_i > 1
125
+ invoke 'puma:phased-restart'
126
+ else
127
+ invoke 'puma:restart'
128
+ end
129
+ end
130
+
131
+ def puma_switch_user(role, &block)
132
+ user = puma_user(role)
133
+ if user == role.user
134
+ block.call
135
+ else
136
+ as user do
137
+ block.call
138
+ end
139
+ end
140
+ end
141
+
142
+ def puma_user(role)
143
+ properties = role.properties
144
+ properties.fetch(:puma_user) || # local property for puma only
145
+ fetch(:puma_user) ||
146
+ properties.fetch(:run_as) || # global property across multiple capistrano gems
147
+ role.user
148
+ end
149
+
150
+ def puma_workers
151
+ fetch(:puma_workers, 0)
152
+ end
153
+
154
+ def puma_preload_app?
155
+ fetch(:puma_preload_app)
156
+ end
157
+
158
+ def puma_bind
159
+ Array(fetch(:puma_bind)).collect do |bind|
160
+ "bind '#{bind}'"
161
+ end.join("\n")
162
+ end
163
+
164
+ def puma_plugins
165
+ Array(fetch(:puma_plugins)).collect do |bind|
166
+ "plugin '#{bind}'"
167
+ end.join("\n")
168
+ end
169
+
170
+ def template_puma(from, to, role)
171
+ [
172
+ "lib/capistrano/templates/#{from}-#{role.hostname}-#{fetch(:stage)}.rb",
173
+ "lib/capistrano/templates/#{from}-#{role.hostname}.rb",
174
+ "lib/capistrano/templates/#{from}-#{fetch(:stage)}.rb",
175
+ "lib/capistrano/templates/#{from}.rb.erb",
176
+ "lib/capistrano/templates/#{from}.rb",
177
+ "lib/capistrano/templates/#{from}.erb",
178
+ "config/deploy/templates/#{from}.rb.erb",
179
+ "config/deploy/templates/#{from}.rb",
180
+ "config/deploy/templates/#{from}.erb",
181
+ File.expand_path("../../templates/#{from}.rb.erb", __FILE__),
182
+ File.expand_path("../../templates/#{from}.erb", __FILE__)
183
+ ].each do |path|
184
+ if File.file?(path)
185
+ erb = File.read(path)
186
+ upload! StringIO.new(ERB.new(erb, nil, '-').result(binding)), to
187
+ break
188
+ end
189
+ end
190
+ end
191
+
192
+ task :add_default_hooks do
193
+ after 'deploy:check', 'puma:check'
194
+ after 'deploy:finished', 'puma:smart_restart'
195
+ end
196
+
197
+ end
@@ -0,0 +1,38 @@
1
+ namespace :puma do
2
+ namespace :workers do
3
+ desc 'Add a worker'
4
+ task :count do
5
+ on roles (fetch(:puma_role)) do |role|
6
+ puma_switch_user(role) do
7
+ #TODO
8
+ # cleanup
9
+ # add host name/ip
10
+ workers_count = capture("ps ax | grep -c 'puma: cluster worker: `cat #{fetch(:puma_pid)}`'").to_i - 1
11
+ log "Workers count : #{workers_count}"
12
+ end
13
+ end
14
+ end
15
+
16
+ # TODO
17
+ # Add/remove workers to specific host/s
18
+ # Define # of workers to add/remove
19
+ # Refactor
20
+ desc 'Worker++'
21
+ task :more do
22
+ on roles (fetch(:puma_role)) do |role|
23
+ puma_switch_user(role) do
24
+ execute(:kill, "-TTIN `cat #{fetch(:puma_pid)}`")
25
+ end
26
+ end
27
+ end
28
+
29
+ desc 'Worker--'
30
+ task :less do
31
+ on roles (fetch(:puma_role)) do |role|
32
+ puma_switch_user(role) do
33
+ execute(:kill, "-TTOU `cat #{fetch(:puma_pid)}`")
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,82 @@
1
+ upstream puma_<%= fetch(:nginx_config_name) %> { <%
2
+ @backends = [fetch(:puma_bind)].flatten.map do |m|
3
+ etype, address = /(tcp|unix|ssl):\/{1,2}(.+)/.match(m).captures
4
+ if etype == 'unix'
5
+ "server #{etype}:#{address} #{fetch(:nginx_socket_flags)};"
6
+ else
7
+ "server #{address.gsub(/0\.0\.0\.0(.+)/, "127.0.0.1\\1")} #{fetch(:nginx_http_flags)};"
8
+ end
9
+ end
10
+ %><% @backends.each do |server| %>
11
+ <%= server %><% end %>
12
+ }
13
+ <% if fetch(:nginx_use_ssl) -%>
14
+ server {
15
+ listen 80;
16
+ server_name <%= fetch(:nginx_server_name) %>;
17
+ rewrite ^(.*) https://$host$1 permanent;
18
+ }
19
+ <% end -%>
20
+
21
+ server {
22
+ <% if fetch(:nginx_use_ssl) -%>
23
+ listen 443;
24
+ ssl on;
25
+ ssl_certificate /etc/ssl/certs/<%= fetch(:nginx_config_name) %>.crt;
26
+ ssl_certificate_key /etc/ssl/private/<%= fetch(:nginx_config_name) %>.key;
27
+ <% else -%>
28
+ listen 80;
29
+ <% end -%>
30
+ server_name <%= fetch(:nginx_server_name) %>;
31
+ root <%= current_path %>/public;
32
+ try_files $uri/index.html $uri @puma_<%= fetch(:nginx_config_name) %>;
33
+
34
+ client_max_body_size 4G;
35
+ keepalive_timeout 10;
36
+
37
+ error_page 500 502 504 /500.html;
38
+ error_page 503 @503;
39
+
40
+ location @puma_<%= fetch(:nginx_config_name) %> {
41
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
42
+ proxy_set_header Host $http_host;
43
+ proxy_redirect off;
44
+ <% if fetch(:nginx_use_ssl) -%>
45
+ proxy_set_header X-Forwarded-Proto https;
46
+ <% end -%>
47
+ proxy_pass http://puma_<%= fetch(:nginx_config_name) %>;
48
+ # limit_req zone=one;
49
+ access_log <%= shared_path %>/log/nginx.access.log;
50
+ error_log <%= shared_path %>/log/nginx.error.log;
51
+ }
52
+
53
+ location ^~ /assets/ {
54
+ gzip_static on;
55
+ expires max;
56
+ add_header Cache-Control public;
57
+ }
58
+
59
+ location = /50x.html {
60
+ root html;
61
+ }
62
+
63
+ location = /404.html {
64
+ root html;
65
+ }
66
+
67
+ location @503 {
68
+ error_page 405 = /system/maintenance.html;
69
+ if (-f $document_root/system/maintenance.html) {
70
+ rewrite ^(.*)$ /system/maintenance.html break;
71
+ }
72
+ rewrite ^(.*)$ /503.html break;
73
+ }
74
+
75
+ if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){
76
+ return 405;
77
+ }
78
+
79
+ if (-f $document_root/system/maintenance.html) {
80
+ return 503;
81
+ }
82
+ }
@@ -0,0 +1,336 @@
1
+ #! /bin/sh
2
+ ### BEGIN INIT INFO
3
+ # Provides: puma
4
+ # Required-Start: $remote_fs $syslog
5
+ # Required-Stop: $remote_fs $syslog
6
+ # Default-Start: 2 3 4 5
7
+ # Default-Stop: 0 1 6
8
+ # Short-Description: Example initscript
9
+ # Description: This file should be used to construct scripts to be
10
+ # placed in /etc/init.d.
11
+ ### END INIT INFO
12
+
13
+ # Author: Darío Javier Cravero <'dario@exordo.com'>
14
+ # Modified by: Abdelkader Boudih <'terminale@gmail.com'>
15
+ #
16
+ # Do NOT "set -e"
17
+
18
+ # PATH should only include /usr/* if it runs after the mountnfs.sh script
19
+ PATH=/usr/local/bin:/usr/local/sbin/:/sbin:/usr/sbin:/bin:/usr/bin
20
+ DESC="Puma rack web server"
21
+ NAME=puma
22
+ DAEMON=$NAME
23
+ SCRIPTNAME=/etc/init.d/$NAME
24
+ CONFIG=<%=fetch(:puma_jungle_conf)%>
25
+ JUNGLE=`cat $CONFIG`
26
+ RUNPUMA=<%=fetch(:puma_run_path)%>
27
+
28
+ # Load the VERBOSE setting and other rcS variables
29
+ . /lib/init/vars.sh
30
+
31
+ # Define LSB log_* functions.
32
+ # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
33
+ . /lib/lsb/init-functions
34
+
35
+ #
36
+ # Function that starts the jungle
37
+ #
38
+ do_start() {
39
+ log_daemon_msg "=> Running the jungle..."
40
+ for i in $JUNGLE; do
41
+ dir=`echo $i | cut -d , -f 1`
42
+ user=`echo $i | cut -d , -f 2`
43
+ config_file=`echo $i | cut -d , -f 3`
44
+ if [ "$config_file" = "" ]; then
45
+ config_file="$dir/config/puma.rb"
46
+ fi
47
+ log_file=`echo $i | cut -d , -f 4`
48
+ if [ "$log_file" = "" ]; then
49
+ log_file="$dir/log/puma.log"
50
+ fi
51
+ do_start_one $dir $user $config_file $log_file
52
+ done
53
+ }
54
+
55
+ do_start_one() {
56
+ PIDFILE=$1/tmp/pids/puma.pid
57
+ if [ -e $PIDFILE ]; then
58
+ PID=`cat $PIDFILE`
59
+ # If the puma isn't running, run it, otherwise restart it.
60
+ if [ "`ps -A -o pid= | grep -c $PID`" -eq 0 ]; then
61
+ do_start_one_do $1 $2
62
+ else
63
+ do_restart_one $1 $2
64
+ fi
65
+ else
66
+ do_start_one_do $1 $2
67
+ fi
68
+ }
69
+
70
+ do_start_one_do() {
71
+ log_daemon_msg "--> Woke up puma $1"
72
+ log_daemon_msg "user $2"
73
+ log_daemon_msg "log to $4"
74
+ log_daemon_msg "start-stop-daemon --verbose --start --chdir $1 --chuid $2 --background --exec $RUNPUMA $1 "
75
+ start-stop-daemon --verbose --start --chdir $1 --chuid $2 --background --exec $RUNPUMA -- $1
76
+ }
77
+
78
+ #
79
+ # Function that stops the jungle
80
+ #
81
+ do_stop() {
82
+ log_daemon_msg "=> Putting all the beasts to bed..."
83
+ for i in $JUNGLE; do
84
+ dir=`echo $i | cut -d , -f 1`
85
+ user=`echo $i | cut -d , -f 2`
86
+ do_stop_one $dir $user
87
+ done
88
+ }
89
+ #
90
+ # Function that stops the daemon/service
91
+ #
92
+ do_stop_one() {
93
+ log_daemon_msg "--> Stopping $1"
94
+ PIDFILE=$1/tmp/pids/puma.pid
95
+ STATEFILE=$1/tmp/pids/puma.state
96
+ if [ -e $PIDFILE ]; then
97
+ PID=`cat $PIDFILE`
98
+ if [ "`ps -A -o pid= | grep -c $PID`" -eq 0 ]; then
99
+ log_daemon_msg "---> Puma $1 isn't running."
100
+ else
101
+ log_daemon_msg "---> About to kill PID `cat $PIDFILE`"
102
+ su - $2 -c "pumactl --state $STATEFILE stop"
103
+ # Many daemons don't delete their pidfiles when they exit.
104
+ rm -f $PIDFILE $STATEFILE
105
+ fi
106
+ else
107
+ log_daemon_msg "---> No puma here..."
108
+ fi
109
+ return 0
110
+ }
111
+
112
+ #
113
+ # Function that restarts the jungle
114
+ #
115
+ do_restart() {
116
+ for i in $JUNGLE; do
117
+ dir=`echo $i | cut -d , -f 1`
118
+ user=`echo $i | cut -d , -f 2`
119
+ do_restart_one $dir $user
120
+ done
121
+ }
122
+
123
+ #
124
+ # Function that sends a SIGUSR2 to the daemon/service
125
+ #
126
+ do_restart_one() {
127
+ PIDFILE=$1/tmp/pids/puma.pid
128
+ i=`grep $1 $CONFIG`
129
+ dir=`echo $i | cut -d , -f 1`
130
+
131
+ if [ -e $PIDFILE ]; then
132
+ log_daemon_msg "--> About to restart puma $1"
133
+ su - $2 -c "pumactl --state $dir/tmp/pids/puma.state restart"
134
+ # kill -s USR2 `cat $PIDFILE`
135
+ # TODO Check if process exist
136
+ else
137
+ log_daemon_msg "--> Your puma was never playing... Let's get it out there first"
138
+ user=`echo $i | cut -d , -f 2`
139
+ config_file=`echo $i | cut -d , -f 3`
140
+ if [ "$config_file" = "" ]; then
141
+ config_file="$dir/config/puma.rb"
142
+ do_start_one $dir $user $config_file
143
+ fi
144
+ log_file=`echo $i | cut -d , -f 4`
145
+ if [ "$log_file" = "" ]; then
146
+ log_file="$dir/log/puma.log"
147
+ fi
148
+ do_start_one $dir $user $config_file $log_file
149
+ fi
150
+ return 0
151
+ }
152
+
153
+ #
154
+ # Function that statuss the jungle
155
+ #
156
+ do_status() {
157
+ for i in $JUNGLE; do
158
+ dir=`echo $i | cut -d , -f 1`
159
+ user=`echo $i | cut -d , -f 2`
160
+ do_status_one $dir $user
161
+ done
162
+ }
163
+
164
+ #
165
+ # Function that sends a SIGUSR2 to the daemon/service
166
+ #
167
+ do_status_one() {
168
+ PIDFILE=$1/tmp/pids/puma.pid
169
+ i=`grep $1 $CONFIG`
170
+ dir=`echo $i | cut -d , -f 1`
171
+
172
+ if [ -e $PIDFILE ]; then
173
+ log_daemon_msg "--> About to status puma $1"
174
+
175
+ su - $2 -c "pumactl --state $dir/tmp/pids/puma.state stats "
176
+
177
+ else
178
+ log_daemon_msg "--> $1 isn't there :(..."
179
+ fi
180
+ return 0
181
+ }
182
+
183
+ do_add() {
184
+ str=""
185
+ # App's directory
186
+ if [ -d "$1" ]; then
187
+ if [ "`grep -c "^$1" $CONFIG`" -eq 0 ]; then
188
+ str=$1
189
+ else
190
+ echo "The app is already being managed. Remove it if you want to update its config."
191
+ exit 0
192
+ fi
193
+ else
194
+ echo "The directory $1 doesn't exist."
195
+ exit 1
196
+ fi
197
+ # User to run it as
198
+ if [ "`grep -c "^$2:" /etc/passwd`" -eq 0 ]; then
199
+ echo "The user $2 doesn't exist."
200
+ exit 1
201
+ else
202
+ str="$str,$2"
203
+ fi
204
+ # Config file
205
+ if [ "$3" != "" ]; then
206
+ if [ -e $3 ]; then
207
+ str="$str,$3"
208
+ else
209
+ echo "The config file $3 doesn't exist."
210
+ exit 1
211
+ fi
212
+ fi
213
+ # Log file
214
+ if [ "$4" != "" ]; then
215
+ str="$str,$4"
216
+ fi
217
+
218
+ # Add it to the jungle
219
+ echo $str >> $CONFIG
220
+ log_daemon_msg "Added a Puma to the jungle: $str. You still have to start it though."
221
+ }
222
+
223
+ do_remove() {
224
+ if [ "`grep -c "^$1" $CONFIG`" -eq 0 ]; then
225
+ echo "There's no app $1 to remove."
226
+ else
227
+ # Stop it first.
228
+ do_stop_one $1
229
+ # Remove it from the config.
230
+ sed -i "\\:^$1:d" $CONFIG
231
+ log_daemon_msg "Removed a Puma from the jungle: $1."
232
+ fi
233
+ }
234
+
235
+ case "$1" in
236
+ start)
237
+ [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
238
+ if [ "$#" -eq 1 ]; then
239
+ do_start
240
+ else
241
+ i=`grep $2 $CONFIG`
242
+ dir=`echo $i | cut -d , -f 1`
243
+ user=`echo $i | cut -d , -f 2`
244
+ config_file=`echo $i | cut -d , -f 3`
245
+ if [ "$config_file" = "" ]; then
246
+ config_file="$dir/config/puma.rb"
247
+
248
+ do_start_one $dir $user $config_file
249
+ fi
250
+ case "$?" in
251
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
252
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
253
+ esac
254
+ fi
255
+ ;;
256
+ stop)
257
+ [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
258
+ if [ "$#" -eq 1 ]; then
259
+ do_stop
260
+ else
261
+ i=`grep $2 $CONFIG`
262
+ dir=`echo $i | cut -d , -f 1`
263
+ do_stop_one $dir
264
+ fi
265
+ case "$?" in
266
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
267
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
268
+ esac
269
+ ;;
270
+ status)
271
+ # TODO Implement.
272
+ log_daemon_msg "Status $DESC" "$NAME"
273
+ if [ "$#" -eq 1 ]; then
274
+ do_status
275
+ else
276
+ i=`grep $2 $CONFIG`
277
+ dir=`echo $i | cut -d , -f 1`
278
+ do_status_one $dir
279
+ fi
280
+ case "$?" in
281
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
282
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
283
+ esac
284
+ ;;
285
+ restart)
286
+ log_daemon_msg "Restarting $DESC" "$NAME"
287
+ if [ "$#" -eq 1 ]; then
288
+ do_restart
289
+ else
290
+ i=`grep $2 $CONFIG`
291
+ dir=`echo $i | cut -d , -f 1`
292
+ do_restart_one $dir
293
+ fi
294
+ case "$?" in
295
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
296
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
297
+ esac
298
+ ;;
299
+ add)
300
+ if [ "$#" -lt 3 ]; then
301
+ echo "Please, specifiy the app's directory and the user that will run it at least."
302
+ echo " Usage: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log"
303
+ echo " config and log are optionals."
304
+ exit 1
305
+ else
306
+ do_add $2 $3 $4 $5
307
+ fi
308
+ case "$?" in
309
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
310
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
311
+ esac
312
+ ;;
313
+ remove)
314
+ if [ "$#" -lt 2 ]; then
315
+ echo "Please, specifiy the app's directory to remove."
316
+ exit 1
317
+ else
318
+ do_remove $2
319
+ fi
320
+ case "$?" in
321
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
322
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
323
+ esac
324
+ ;;
325
+ *)
326
+ echo "Usage:" >&2
327
+ echo " Run the jungle: $SCRIPTNAME {start|stop|status|restart}" >&2
328
+ echo " Add a Puma: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log"
329
+ echo " config and log are optionals."
330
+ echo " Remove a Puma: $SCRIPTNAME remove /path/to/app"
331
+ echo " On a Puma: $SCRIPTNAME {start|stop|status|restart} PUMA-NAME" >&2
332
+ exit 3
333
+ ;;
334
+ esac
335
+ :
336
+