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,328 @@
1
+ #!/bin/sh
2
+ #
3
+ # puma - this script starts and stops the puma daemon
4
+ #
5
+ # chkconfig: - 85 15
6
+ # description: Description \
7
+ # goes here...
8
+ # processname: puma
9
+ # config: /etc/puma.conf
10
+ # pidfile: /home/stanislaw/apps/micro-apps/puma/puma.pid
11
+ # Author: Darío Javier Cravero <'dario@exordo.com'>
12
+ #
13
+ # Do NOT "set -e"
14
+ # Original script https://github.com/puma/puma/blob/master/tools/jungle/puma
15
+ # It was modified here by Stanislaw Pankevich <'s.pankevich@gmail.com'>
16
+ # to run on CentOS 5.5 boxes.
17
+ # Script works perfectly on CentOS 5: script uses its native daemon().
18
+ # Puma is being stopped/restarted by sending signals, control app is not used.
19
+ # Source function library.
20
+ . /etc/rc.d/init.d/functions
21
+
22
+ # Source networking configuration.
23
+ . /etc/sysconfig/network
24
+ # Check that networking is up.
25
+ [ "$NETWORKING" = "no" ] && exit 0
26
+ # PATH should only include /usr/* if it runs after the mountnfs.sh script
27
+ PATH=/usr/local/bin:/usr/local/sbin/:/sbin:/usr/sbin:/bin:/usr/bin
28
+ DESC="Puma rack web server"
29
+ NAME=puma
30
+ DAEMON=$NAME
31
+ SCRIPTNAME=/etc/init.d/$NAME
32
+ CONFIG=<%=fetch(:puma_jungle_conf)%>
33
+ JUNGLE=`cat $CONFIG`
34
+ RUNPUMA=<%=fetch(:puma_run_path)%>
35
+ # Skipping the following non-CentOS string
36
+ # Load the VERBOSE setting and other rcS variables
37
+ # . /lib/init/vars.sh
38
+ # CentOS does not have these functions natively
39
+ log_daemon_msg() { echo "$@"; }
40
+ log_end_msg() { [ $1 -eq 0 ] && RES=OK; logger ${RES:=FAIL}; }
41
+ # Define LSB log_* functions.
42
+ # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
43
+ . /lib/lsb/init-functions
44
+
45
+ #
46
+ # Function that starts the jungle
47
+ #
48
+ do_start() {
49
+ log_daemon_msg "=> Running the jungle..."
50
+ for i in $JUNGLE; do
51
+ dir=`echo $i | cut -d , -f 1`
52
+ user=`echo $i | cut -d , -f 2`
53
+ config_file=`echo $i | cut -d , -f 3`
54
+ if [ "$config_file" = "" ]; then
55
+ config_file="$dir/config/puma.rb"
56
+ fi
57
+ log_file=`echo $i | cut -d , -f 4`
58
+ if [ "$log_file" = "" ]; then
59
+ log_file="$dir/log/puma.log"
60
+ fi
61
+ do_start_one $dir $user $config_file $log_file
62
+ done
63
+ }
64
+ do_start_one() {
65
+ PIDFILE=$1/tmp/pids/puma.pid
66
+ if [ -e $PIDFILE ]; then
67
+ PID=`cat $PIDFILE`
68
+ # If the puma isn't running, run it, otherwise restart it.
69
+ if [ "`ps -A -o pid= | grep -c $PID`" -eq 0 ]; then
70
+ do_start_one_do $1 $2
71
+ else
72
+ do_restart_one $1
73
+ fi
74
+ else
75
+ do_start_one_do $1 $2 $3 $4
76
+ fi
77
+ }
78
+ do_start_one_do() {
79
+ log_daemon_msg "--> Woke up puma $1"
80
+ daemon --user $2 $RUNPUMA $1
81
+ }
82
+ #
83
+ # Function that stops the jungle
84
+ #
85
+ do_stop() {
86
+ log_daemon_msg "=> Putting all the beasts to bed..."
87
+ for i in $JUNGLE; do
88
+ dir=`echo $i | cut -d , -f 1`
89
+ do_stop_one $dir
90
+ done
91
+ }
92
+ #
93
+ # Function that stops the daemon/service
94
+ #
95
+ do_stop_one() {
96
+ log_daemon_msg "--> Stopping $1"
97
+ PIDFILE=$1/tmp/pids/puma.pid
98
+ STATEFILE=$1/tmp/pids/puma.state
99
+ echo $PIDFILE
100
+ if [ -e $PIDFILE ]; then
101
+ PID=`cat $PIDFILE`
102
+ echo "Pid:"
103
+ echo $PID
104
+ if [ "`ps -A -o pid= | grep -c $PID`" -eq 0 ]; then
105
+ log_daemon_msg "---> Puma $1 isn't running."
106
+ else
107
+ log_daemon_msg "---> About to kill PID `cat $PIDFILE`"
108
+ pumactl --state $STATEFILE stop
109
+ rm -f $PIDFILE $STATEFILE
110
+ fi
111
+ else
112
+ log_daemon_msg "---> No puma here..."
113
+ fi
114
+ return 0
115
+ }
116
+ #
117
+ # Function that restarts the jungle
118
+ #
119
+ do_restart() {
120
+ for i in $JUNGLE; do
121
+ dir=`echo $i | cut -d , -f 1`
122
+ do_restart_one $dir
123
+ done
124
+ }
125
+ #
126
+ # Function that sends a SIGUSR2 to the daemon/service
127
+ #
128
+ do_restart_one() {
129
+ PIDFILE=$1/tmp/pids/puma.pid
130
+ i=`grep $1 $CONFIG`
131
+ dir=`echo $i | cut -d , -f 1`
132
+ if [ -e $PIDFILE ]; then
133
+ log_daemon_msg "--> About to restart puma $1"
134
+ pumactl --state $dir/tmp/pids/puma.state restart
135
+
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
+ fi
143
+ log_file=`echo $i | cut -d , -f 4`
144
+ if [ "$log_file" = "" ]; then
145
+ log_file="$dir/log/puma.log"
146
+ fi
147
+ do_start_one $dir $user $config_file $log_file
148
+ fi
149
+ return 0
150
+ }
151
+ #
152
+ # Function that statuss then jungle
153
+ #
154
+ do_status() {
155
+ for i in $JUNGLE; do
156
+ dir=`echo $i | cut -d , -f 1`
157
+ do_status_one $dir
158
+ done
159
+ }
160
+ #
161
+ # Function that sends a SIGUSR2 to the daemon/service
162
+ #
163
+ do_status_one() {
164
+ PIDFILE=$1/tmp/pids/puma.pid
165
+ i=`grep $1 $CONFIG`
166
+ dir=`echo $i | cut -d , -f 1`
167
+ if [ -e $PIDFILE ]; then
168
+ log_daemon_msg "--> About to status puma $1"
169
+ pumactl --state $dir/tmp/pids/puma.state stats
170
+
171
+ else
172
+ log_daemon_msg "--> $1 isn't there :(..."
173
+ fi
174
+ return 0
175
+ }
176
+ do_add() {
177
+ str=""
178
+ # App's directory
179
+ if [ -d "$1" ]; then
180
+ if [ "`grep -c "^$1" $CONFIG`" -eq 0 ]; then
181
+ str=$1
182
+ else
183
+ echo "The app is already being managed. Remove it if you want to update its config."
184
+ exit 1
185
+ fi
186
+ else
187
+ echo "The directory $1 doesn't exist."
188
+ exit 1
189
+ fi
190
+ # User to run it as
191
+ if [ "`grep -c "^$2:" /etc/passwd`" -eq 0 ]; then
192
+ echo "The user $2 doesn't exist."
193
+ exit 1
194
+ else
195
+ str="$str,$2"
196
+ fi
197
+ # Config file
198
+ if [ "$3" != "" ]; then
199
+ if [ -e $3 ]; then
200
+ str="$str,$3"
201
+ else
202
+ echo "The config file $3 doesn't exist."
203
+ exit 1
204
+ fi
205
+ fi
206
+ # Log file
207
+ if [ "$4" != "" ]; then
208
+ str="$str,$4"
209
+ fi
210
+ # Add it to the jungle
211
+ echo $str >> $CONFIG
212
+ log_daemon_msg "Added a Puma to the jungle: $str. You still have to start it though."
213
+ }
214
+ do_remove() {
215
+ if [ "`grep -c "^$1" $CONFIG`" -eq 0 ]; then
216
+ echo "There's no app $1 to remove."
217
+ else
218
+ # Stop it first.
219
+ do_stop_one $1
220
+ # Remove it from the config.
221
+ sed -i "\\:^$1:d" $CONFIG
222
+ log_daemon_msg "Removed a Puma from the jungle: $1."
223
+ fi
224
+ }
225
+ case "$1" in
226
+ start)
227
+ [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
228
+ if [ "$#" -eq 1 ]; then
229
+ do_start
230
+ else
231
+ i=`grep $2 $CONFIG`
232
+ dir=`echo $i | cut -d , -f 1`
233
+ user=`echo $i | cut -d , -f 2`
234
+ config_file=`echo $i | cut -d , -f 3`
235
+ if [ "$config_file" = "" ]; then
236
+ config_file="$dir/config/puma.rb"
237
+ fi
238
+ log_file=`echo $i | cut -d , -f 4`
239
+ if [ "$log_file" = "" ]; then
240
+ log_file="$dir/log/puma.log"
241
+ fi
242
+ do_start_one $dir $user $config_file $log_file
243
+ fi
244
+ case "$?" in
245
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
246
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
247
+ esac
248
+ ;;
249
+ stop)
250
+ [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
251
+ if [ "$#" -eq 1 ]; then
252
+ do_stop
253
+ else
254
+ i=`grep $2 $CONFIG`
255
+ dir=`echo $i | cut -d , -f 1`
256
+ do_stop_one $dir
257
+ fi
258
+ case "$?" in
259
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
260
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
261
+ esac
262
+ ;;
263
+ status)
264
+ # TODO Implement.
265
+ log_daemon_msg "Status $DESC" "$NAME"
266
+ if [ "$#" -eq 1 ]; then
267
+ do_status
268
+ else
269
+ i=`grep $2 $CONFIG`
270
+ dir=`echo $i | cut -d , -f 1`
271
+ do_status_one $dir
272
+ fi
273
+ case "$?" in
274
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
275
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
276
+ esac
277
+ ;;
278
+ restart)
279
+ log_daemon_msg "Restarting $DESC" "$NAME"
280
+ if [ "$#" -eq 1 ]; then
281
+ do_restart
282
+ else
283
+ i=`grep $2 $CONFIG`
284
+ dir=`echo $i | cut -d , -f 1`
285
+ do_restart_one $dir
286
+ fi
287
+ case "$?" in
288
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
289
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
290
+ esac
291
+ ;;
292
+ add)
293
+ if [ "$#" -lt 3 ]; then
294
+ echo "Please, specifiy the app's directory and the user that will run it at least."
295
+ echo " Usage: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log"
296
+ echo " config and log are optionals."
297
+ exit 1
298
+ else
299
+ do_add $2 $3 $4 $5
300
+ fi
301
+ case "$?" in
302
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
303
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
304
+ esac
305
+ ;;
306
+ remove)
307
+ if [ "$#" -lt 2 ]; then
308
+ echo "Please, specifiy the app's directory to remove."
309
+ exit 1
310
+ else
311
+ do_remove $2
312
+ fi
313
+ case "$?" in
314
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
315
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
316
+ esac
317
+ ;;
318
+ *)
319
+ echo "Usage:" >&2
320
+ echo " Run the jungle: $SCRIPTNAME {start|stop|status|restart}" >&2
321
+ echo " Add a Puma: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log"
322
+ echo " config and log are optionals."
323
+ echo " Remove a Puma: $SCRIPTNAME remove /path/to/app"
324
+ echo " On a Puma: $SCRIPTNAME {start|stop|status|restart} PUMA-NAME" >&2
325
+ exit 3
326
+ ;;
327
+ esac
328
+ :
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env puma
2
+
3
+ directory '<%= current_path %>'
4
+ rackup "<%=fetch(:puma_rackup)%>"
5
+ environment '<%= fetch(:puma_env) %>'
6
+ <% if fetch(:puma_tag) %>
7
+ tag '<%= fetch(:puma_tag)%>'
8
+ <% end %>
9
+ pidfile "<%=fetch(:puma_pid)%>"
10
+ state_path "<%=fetch(:puma_state)%>"
11
+ stdout_redirect '<%=fetch(:puma_access_log)%>', '<%=fetch(:puma_error_log)%>', true
12
+
13
+
14
+ threads <%=fetch(:puma_threads).join(',')%>
15
+
16
+ <%= puma_plugins %>
17
+
18
+ <%= puma_bind %>
19
+ <% if fetch(:puma_control_app) %>
20
+ activate_control_app "<%= fetch(:puma_default_control_app) %>"
21
+ <% end %>
22
+ workers <%= puma_workers %>
23
+ <% if fetch(:puma_worker_timeout) %>
24
+ worker_timeout <%= fetch(:puma_worker_timeout).to_i %>
25
+ <% end %>
26
+
27
+ <% if puma_preload_app? %>
28
+ preload_app!
29
+ <% else %>
30
+ prune_bundler
31
+ <% end %>
32
+
33
+ on_restart do
34
+ puts 'Refreshing Gemfile'
35
+ ENV["BUNDLE_GEMFILE"] = "<%= fetch(:bundle_gemfile, "#{current_path}/Gemfile") %>"
36
+ end
37
+
38
+ <% if puma_preload_app? and fetch(:puma_init_active_record) %>
39
+ before_fork do
40
+ ActiveRecord::Base.connection_pool.disconnect!
41
+ end
42
+
43
+ on_worker_boot do
44
+ ActiveSupport.on_load(:active_record) do
45
+ ActiveRecord::Base.establish_connection
46
+ end
47
+ end
48
+ <% end %>
@@ -0,0 +1,7 @@
1
+ # Monit configuration for Puma
2
+ # Service name: <%= puma_monit_service_name %>
3
+ #
4
+ check process <%= puma_monit_service_name %>
5
+ with pidfile "<%= fetch(:puma_pid) %>"
6
+ start program = "/usr/bin/sudo -iu <%= puma_user(@role) %> /bin/bash -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:puma] %> -C <%= fetch(:puma_conf) %> --daemon'"
7
+ stop program = "/usr/bin/sudo -iu <%= puma_user(@role) %> /bin/bash -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:pumactl] %> -S <%= fetch(:puma_state) %> stop'"
@@ -0,0 +1,9 @@
1
+ #!/bin/bash
2
+ app=$1;
3
+ cd $app || exit 1
4
+
5
+ if [ -e Gemfile ]; then
6
+ exec <%= fetch(:puma_user) ? "sudo -u #{puma_user(@role)}" : '' %> sh -c "exec bundle exec puma -C <%= fetch(:puma_conf) %> --daemon"
7
+ else
8
+ exec <%= fetch(:puma_user) ? "sudo -u #{puma_user(@role)}" : '' %> sh -c "exec puma -C <%= fetch(:puma_conf) %> --daemon"
9
+ fi
File without changes
@@ -0,0 +1,9 @@
1
+ To create local nginx and puma configuration files call
2
+
3
+ rails generate capistrano:nginx_puma:config [path]
4
+
5
+ The default path is "config/deploy/templates". You can override it like so:
6
+
7
+ rails generate capistrano:nginx_puma:config "config/templates"
8
+
9
+ If you override templates path, don't forget to set "templates_path" variable in your deploy.rb
@@ -0,0 +1,21 @@
1
+ module Capistrano
2
+ module NginxPuma
3
+ module Generators
4
+ class ConfigGenerator < Rails::Generators::Base
5
+ desc "Create local nginx and puma configuration files for customization"
6
+ source_root File.expand_path('../templates', __FILE__)
7
+ argument :templates_path, :type => :string,
8
+ :default => "config/deploy/templates",
9
+ :banner => "path to templates"
10
+
11
+ def copy_template
12
+ copy_file "../../../../capistrano/templates/puma.rb.erb", "#{templates_path}/puma.rb.erb"
13
+ copy_file "../../../../capistrano/templates/nginx_conf.erb", "#{templates_path}/nginx_conf.erb"
14
+ # copy_file "puma.rb.erb", "#{templates_path}/puma.rb.erb"
15
+ # copy_file "puma_init.erb", "#{templates_path}/puma_init.erb"
16
+ # copy_file "logrotate.erb", "#{templates_path}/logrotate.erb"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-puma-a
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Abdelkader Boudih
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: capistrano-bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: puma
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ description: A clone of seuros/capistrano-puma used here for version bump
56
+ email:
57
+ - Terminale@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CHANGELOG.md
64
+ - CONTRIBUTORS.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - capistrano-puma-a.gemspec
70
+ - lib/capistrano/puma.rb
71
+ - lib/capistrano/puma/jungle.rb
72
+ - lib/capistrano/puma/monit.rb
73
+ - lib/capistrano/puma/nginx.rb
74
+ - lib/capistrano/puma/version.rb
75
+ - lib/capistrano/puma/workers.rb
76
+ - lib/capistrano/tasks/jungle.rake
77
+ - lib/capistrano/tasks/monit.rake
78
+ - lib/capistrano/tasks/nginx.rake
79
+ - lib/capistrano/tasks/puma.rake
80
+ - lib/capistrano/tasks/workers.rake
81
+ - lib/capistrano/templates/nginx_conf.erb
82
+ - lib/capistrano/templates/puma-deb.erb
83
+ - lib/capistrano/templates/puma-rpm.erb
84
+ - lib/capistrano/templates/puma.rb.erb
85
+ - lib/capistrano/templates/puma_monit.conf.erb
86
+ - lib/capistrano/templates/run-puma.erb
87
+ - lib/capistrano3-puma.rb
88
+ - lib/generators/capistrano/nginx_puma/USAGE
89
+ - lib/generators/capistrano/nginx_puma/config_generator.rb
90
+ homepage: https://github.com/seuros/capistrano-puma
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 1.9.3
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.8
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Puma integration for Capistrano
114
+ test_files: []