capistrano3-puma 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e2faa760ffae1290576f528f6108b2eee9043b4d
4
+ data.tar.gz: 71937a3ba57f88c3c0f235d57a17956ee9f94ec8
5
+ SHA512:
6
+ metadata.gz: 3dfeb25613924201beabe6e40918791fe8dcf4bda0683f4fdfe66f0918ec8edada386ec7d3aa09248175ee47c79f12cfbb9aba85d63c867bd88d84157d4e5946
7
+ data.tar.gz: 854ceb68a80b8ad7b860f83c36d8b909abb9df04492f47d764cbf936dbc5ee358ba301ae9d1130289d1ba7222a378d9daa4beb32eb58a513302e1c0a666fe01a
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .idea
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-puma.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Abdelkader Boudih
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Capistrano::Puma
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ gem 'capistrano-puma', github: "seuros/capistrano-puma"
8
+
9
+ And then execute:
10
+
11
+ $ bundle
12
+
13
+ ## Usage
14
+
15
+ # Capfile
16
+
17
+ require 'capistrano/puma'
18
+ require 'capistrano/puma/jungle' #if you need the jungle tasks
19
+
20
+
21
+
22
+ Configurable options, shown here with defaults:
23
+
24
+ set :puma_state, "#{shared_path}/tmp/pids/puma.state"
25
+ set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
26
+ set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock"
27
+ set :puma_conf, "#{shared_path}/config/puma.rb"
28
+ set :puma_access_log, "#{shared_path}/log/puma_error.log"
29
+ set :puma_error_log, "#{shared_path}/log/puma_access.log"
30
+ set :puma_role, :app
31
+ set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production'))
32
+ set :puma_threads, [0, 16]
33
+ set :puma_workers, 0
34
+
35
+ For RVM users, it is advisable to set in your deploy.rb for now :
36
+ set :puma_cmd, "#{fetch(:bundle_cmd, 'bundle')} exec puma"
37
+ set :pumactl_cmd, "#{fetch(:bundle_cmd, 'bundle')} exec pumactl"
38
+
39
+
40
+
41
+ ## Contributors
42
+
43
+ [molfar](https://github.com/molfar)
44
+
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ # This file is kept for backward compatibility only.
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'capistrano/puma/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'capistrano-puma'
9
+ spec.version = Capistrano::Puma::VERSION
10
+ spec.authors = ['Abdelkader Boudih']
11
+ spec.email = ['Terminale@gmail.com']
12
+ spec.description = %q{Puma integration for Capistrano 3}
13
+ spec.summary = %q{Puma integration for Capistrano}
14
+ spec.homepage = 'https://github.com/seuros/capistrano-puma'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'capistrano', '~> 3.0.0'
21
+
22
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/puma/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'capistrano3-puma'
8
+ spec.version = Capistrano::Puma::VERSION
9
+ spec.authors = ['Abdelkader Boudih']
10
+ spec.email = ['Terminale@gmail.com']
11
+ spec.description = %q{Puma integration for Capistrano 3}
12
+ spec.summary = %q{Puma integration for Capistrano}
13
+ spec.homepage = 'https://github.com/seuros/capistrano-puma'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_dependency 'capistrano', '~> 3.0.0'
20
+
21
+ end
File without changes
@@ -0,0 +1 @@
1
+ load File.expand_path('../tasks/puma.cap', __FILE__)
@@ -0,0 +1,2 @@
1
+ #load jungle tasks
2
+ load File.expand_path('../../tasks/jungle.cap', __FILE__)
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Puma
3
+ VERSION = '0.0.7'
4
+ end
5
+ end
@@ -0,0 +1,81 @@
1
+ namespace :load do
2
+ task :defaults do
3
+ set :puma_jungle_conf, '/etc/puma.conf'
4
+ set :puma_run_path, '/usr/local/bin/run-puma'
5
+ end
6
+ end
7
+
8
+
9
+ namespace :puma do
10
+ namespace :jungle do
11
+
12
+ desc 'Install Puma jungle'
13
+ task :install do
14
+ on roles(fetch(:puma_role)) do
15
+ template_puma 'run-puma.erb', "#{fetch(:tmp_dir)}/run-puma"
16
+ execute "chmod +x #{fetch(:tmp_dir)}/run-puma"
17
+ sudo "mv #{fetch(:tmp_dir)}/run-puma #{fetch(:puma_run_path)}"
18
+ if test "[ -f /etc/lsb-release ]"
19
+ #Debian flavor OS
20
+ debian_install
21
+ elsif test "[ -f /etc/redhat-release ]"
22
+ #RHEL flavor OS
23
+ rhel_install
24
+ else
25
+ #Some other OS
26
+ #TODO write in the error log
27
+ puts 'This task is not supported for your OS'
28
+ end
29
+ sudo "touch #{fetch(:puma_jungle_conf)}"
30
+ end
31
+ end
32
+
33
+
34
+ def debian_install
35
+ template_puma 'puma-deb.erb', "#{fetch(:tmp_dir)}/puma"
36
+ execute "chmod +x #{fetch(:tmp_dir)}/puma"
37
+ sudo "mv #{fetch(:tmp_dir)}/puma /etc/init.d/puma"
38
+ sudo "update-rc.d -f puma defaults"
39
+
40
+ end
41
+
42
+ def rhel_install
43
+ template_puma 'puma-rpm.erb', "#{fetch(:tmp_dir)}/puma"
44
+ execute "chmod +x #{fetch(:tmp_dir)}/puma"
45
+ sudo "mv #{fetch(:tmp_dir)}/puma /etc/init.d/puma"
46
+ sudo "chkconfig --add puma"
47
+ end
48
+
49
+
50
+ desc 'Setup Puma config and install jungle script'
51
+ task :setup do
52
+ invoke 'puma:config'
53
+ invoke 'puma:jungle:install'
54
+ invoke 'puma:jungle:add'
55
+ end
56
+
57
+ desc 'Add current project to the jungle'
58
+ task :add do
59
+ on roles(fetch(:puma_role)) do|role|
60
+ sudo "/etc/init.d/puma add '#{current_path}' #{fetch(:puma_user, role.user)}"
61
+ end
62
+ end
63
+
64
+ desc 'Remove current project from the jungle'
65
+ task :remove do
66
+ on roles(fetch(:puma_role)) do
67
+ sudo "/etc/init.d/puma remove '#{current_path}'"
68
+ end
69
+ end
70
+
71
+ %w[start stop restart status].each do |command|
72
+ desc "#{command} puma"
73
+ task command do
74
+ on roles(fetch(:puma_role)) do
75
+ sudo "service puma #{command} #{current_path}"
76
+ end
77
+ end
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,69 @@
1
+ namespace :deploy do
2
+ after :finished, 'puma:restart'
3
+ end
4
+
5
+ namespace :load do
6
+ task :defaults do
7
+ set :puma_role, :app
8
+ set :puma_env, -> { fetch(:rack_env, fetch(:rails_env, 'production')) }
9
+ # Configure "min" to be the minimum number of threads to use to answer
10
+ # requests and "max" the maximum.
11
+ set :puma_threads, [0, 16]
12
+ set :puma_workers, 0
13
+ set :puma_state, -> { File.join(shared_path, 'tmp', 'pids', 'puma.state') }
14
+ set :puma_pid, -> { File.join(shared_path, 'tmp', 'pids', 'puma.pid') }
15
+ set :puma_bind, -> { File.join('unix://', shared_path, 'tmp', 'sockets', 'puma.sock') }
16
+ set :puma_conf, -> { File.join(shared_path, 'config', 'puma.rb') }
17
+ set :puma_access_log, -> { File.join(shared_path, 'log', 'puma_error.log') }
18
+ set :puma_error_log, -> { File.join(shared_path, 'log', 'puma_access.log') }
19
+
20
+ # Rbenv and RVM integration
21
+ set :rbenv_map_bins, fetch(:rbenv_map_bins).to_a.concat(%w{ puma pumactl })
22
+ set :rvm_map_bins, fetch(:rvm_map_bins).to_a.concat(%w{ puma pumactl })
23
+ end
24
+ end
25
+
26
+ namespace :puma do
27
+
28
+ desc 'Setup Puma config file'
29
+ task :config do
30
+ on roles(fetch(:puma_role)) do
31
+ template_puma 'puma.rb.erb', fetch(:puma_conf)
32
+ end
33
+ end
34
+
35
+ desc 'Start puma'
36
+ task :start do
37
+ on roles (fetch(:puma_role)) do
38
+ within current_path do
39
+ # RVM has issues with bundler
40
+ if fetch(:puma_cmd)
41
+ execute "#{fetch(:puma_cmd)} -C #{fetch(:puma_conf)}"
42
+ else
43
+ execute :puma, "-C #{fetch(:puma_conf)}"
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ %w[halt stop restart phased-restart status].each do |command|
50
+ desc "#{command} puma"
51
+ task command do
52
+ on roles (fetch(:puma_role)) do
53
+ within current_path do
54
+ # RVM has issues with bundler
55
+ if fetch(:pumactl_cmd)
56
+ execute "#{fetch(:pumactl_cmd)} -S #{fetch(:puma_state)} #{command}"
57
+ else
58
+ execute :pumactl, "-S #{fetch(:puma_state)} #{command}"
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ def template_puma(from, to)
66
+ erb = File.read(File.expand_path("../../templates/#{from}", __FILE__))
67
+ upload! StringIO.new(ERB.new(erb).result(binding)), to
68
+ end
69
+ end
@@ -0,0 +1,333 @@
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
+ #
15
+ # Do NOT "set -e"
16
+
17
+ # PATH should only include /usr/* if it runs after the mountnfs.sh script
18
+ PATH=/usr/local/bin:/usr/local/sbin/:/sbin:/usr/sbin:/bin:/usr/bin
19
+ DESC="Puma rack web server"
20
+ NAME=puma
21
+ DAEMON=$NAME
22
+ SCRIPTNAME=/etc/init.d/$NAME
23
+ CONFIG=<%=fetch(:puma_jungle_conf)%>
24
+ JUNGLE=`cat $CONFIG`
25
+ RUNPUMA=<%=fetch(:puma_run_path)%>
26
+
27
+ # Load the VERBOSE setting and other rcS variables
28
+ . /lib/init/vars.sh
29
+
30
+ # Define LSB log_* functions.
31
+ # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
32
+ . /lib/lsb/init-functions
33
+
34
+ #
35
+ # Function that starts the jungle
36
+ #
37
+ do_start() {
38
+ log_daemon_msg "=> Running the jungle..."
39
+ for i in $JUNGLE; do
40
+ dir=`echo $i | cut -d , -f 1`
41
+ user=`echo $i | cut -d , -f 2`
42
+ config_file=`echo $i | cut -d , -f 3`
43
+ if [ "$config_file" = "" ]; then
44
+ config_file="$dir/config/puma.rb"
45
+ fi
46
+ log_file=`echo $i | cut -d , -f 4`
47
+ if [ "$log_file" = "" ]; then
48
+ log_file="$dir/log/puma.log"
49
+ fi
50
+ do_start_one $dir $user $config_file $log_file
51
+ done
52
+ }
53
+
54
+ do_start_one() {
55
+ PIDFILE=$1/tmp/pids/puma.pid
56
+ if [ -e $PIDFILE ]; then
57
+ PID=`cat $PIDFILE`
58
+ # If the puma isn't running, run it, otherwise restart it.
59
+ if [ "`ps -A -o pid= | grep -c $PID`" -eq 0 ]; then
60
+ do_start_one_do $1 $2
61
+ else
62
+ do_restart_one $1
63
+ fi
64
+ else
65
+ do_start_one_do $1 $2
66
+ fi
67
+ }
68
+
69
+ do_start_one_do() {
70
+ log_daemon_msg "--> Woke up puma $1"
71
+ log_daemon_msg "user $2"
72
+ log_daemon_msg "log to $4"
73
+ log_daemon_msg "start-stop-daemon --verbose --start --chdir $1 --chuid $2 --background --exec $RUNPUMA -- $1 "
74
+ start-stop-daemon --verbose --start --chdir $1 --chuid $2 --background --exec $RUNPUMA -- $1
75
+ }
76
+
77
+ #
78
+ # Function that stops the jungle
79
+ #
80
+ do_stop() {
81
+ log_daemon_msg "=> Putting all the beasts to bed..."
82
+ for i in $JUNGLE; do
83
+ dir=`echo $i | cut -d , -f 1`
84
+ do_stop_one $dir
85
+ done
86
+ }
87
+ #
88
+ # Function that stops the daemon/service
89
+ #
90
+ do_stop_one() {
91
+ log_daemon_msg "--> Stopping $1"
92
+ PIDFILE=$1/tmp/pids/puma.pid
93
+ STATEFILE=$1/tmp/pids/puma.state
94
+ if [ -e $PIDFILE ]; then
95
+ PID=`cat $PIDFILE`
96
+ if [ "`ps -A -o pid= | grep -c $PID`" -eq 0 ]; then
97
+ log_daemon_msg "---> Puma $1 isn't running."
98
+ else
99
+ log_daemon_msg "---> About to kill PID `cat $PIDFILE`"
100
+ pumactl --state $STATEFILE stop
101
+ # Many daemons don't delete their pidfiles when they exit.
102
+ rm -f $PIDFILE $STATEFILE
103
+ fi
104
+ else
105
+ log_daemon_msg "---> No puma here..."
106
+ fi
107
+ return 0
108
+ }
109
+
110
+ #
111
+ # Function that restarts the jungle
112
+ #
113
+ do_restart() {
114
+ for i in $JUNGLE; do
115
+ dir=`echo $i | cut -d , -f 1`
116
+ do_restart_one $dir
117
+ done
118
+ }
119
+
120
+ #
121
+ # Function that sends a SIGUSR2 to the daemon/service
122
+ #
123
+ do_restart_one() {
124
+ PIDFILE=$1/tmp/pids/puma.pid
125
+ i=`grep $1 $CONFIG`
126
+ dir=`echo $i | cut -d , -f 1`
127
+
128
+ if [ -e $PIDFILE ]; then
129
+ log_daemon_msg "--> About to restart puma $1"
130
+ pumactl --state $dir/tmp/pids/puma.state restart
131
+ # kill -s USR2 `cat $PIDFILE`
132
+ # TODO Check if process exist
133
+ else
134
+ log_daemon_msg "--> Your puma was never playing... Let's get it out there first"
135
+ user=`echo $i | cut -d , -f 2`
136
+ config_file=`echo $i | cut -d , -f 3`
137
+ if [ "$config_file" = "" ]; then
138
+ config_file="$dir/config/puma.rb"
139
+ fi
140
+ log_file=`echo $i | cut -d , -f 4`
141
+ if [ "$log_file" = "" ]; then
142
+ log_file="$dir/log/puma.log"
143
+ fi
144
+ do_start_one $dir $user $config_file $log_file
145
+ fi
146
+ return 0
147
+ }
148
+
149
+ #
150
+ # Function that statuss the jungle
151
+ #
152
+ do_status() {
153
+ for i in $JUNGLE; do
154
+ dir=`echo $i | cut -d , -f 1`
155
+ do_status_one $dir
156
+ done
157
+ }
158
+
159
+ #
160
+ # Function that sends a SIGUSR2 to the daemon/service
161
+ #
162
+ do_status_one() {
163
+ PIDFILE=$1/tmp/pids/puma.pid
164
+ i=`grep $1 $CONFIG`
165
+ dir=`echo $i | cut -d , -f 1`
166
+
167
+ if [ -e $PIDFILE ]; then
168
+ log_daemon_msg "--> About to status puma $1"
169
+ pumactl --state $dir/tmp/pids/puma.state stats
170
+ # kill -s USR2 `cat $PIDFILE`
171
+ # TODO Check if process exist
172
+ else
173
+ log_daemon_msg "--> $1 isn't there :(..."
174
+ fi
175
+ return 0
176
+ }
177
+
178
+ do_add() {
179
+ str=""
180
+ # App's directory
181
+ if [ -d "$1" ]; then
182
+ if [ "`grep -c "^$1" $CONFIG`" -eq 0 ]; then
183
+ str=$1
184
+ else
185
+ echo "The app is already being managed. Remove it if you want to update its config."
186
+ exit 0
187
+ fi
188
+ else
189
+ echo "The directory $1 doesn't exist."
190
+ exit 1
191
+ fi
192
+ # User to run it as
193
+ if [ "`grep -c "^$2:" /etc/passwd`" -eq 0 ]; then
194
+ echo "The user $2 doesn't exist."
195
+ exit 1
196
+ else
197
+ str="$str,$2"
198
+ fi
199
+ # Config file
200
+ if [ "$3" != "" ]; then
201
+ if [ -e $3 ]; then
202
+ str="$str,$3"
203
+ else
204
+ echo "The config file $3 doesn't exist."
205
+ exit 1
206
+ fi
207
+ fi
208
+ # Log file
209
+ if [ "$4" != "" ]; then
210
+ str="$str,$4"
211
+ fi
212
+
213
+ # Add it to the jungle
214
+ echo $str >> $CONFIG
215
+ log_daemon_msg "Added a Puma to the jungle: $str. You still have to start it though."
216
+ }
217
+
218
+ do_remove() {
219
+ if [ "`grep -c "^$1" $CONFIG`" -eq 0 ]; then
220
+ echo "There's no app $1 to remove."
221
+ else
222
+ # Stop it first.
223
+ do_stop_one $1
224
+ # Remove it from the config.
225
+ sed -i "\\:^$1:d" $CONFIG
226
+ log_daemon_msg "Removed a Puma from the jungle: $1."
227
+ fi
228
+ }
229
+
230
+ case "$1" in
231
+ start)
232
+ [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
233
+ if [ "$#" -eq 1 ]; then
234
+ do_start
235
+ else
236
+ i=`grep $2 $CONFIG`
237
+ dir=`echo $i | cut -d , -f 1`
238
+ user=`echo $i | cut -d , -f 2`
239
+ config_file=`echo $i | cut -d , -f 3`
240
+ if [ "$config_file" = "" ]; then
241
+ config_file="$dir/config/puma.rb"
242
+ fi
243
+ log_file=`echo $i | cut -d , -f 4`
244
+ if [ "$log_file" = "" ]; then
245
+ log_file="$dir/log/puma.log"
246
+ fi
247
+ do_start_one $dir $user $config_file $log_file
248
+ fi
249
+ case "$?" in
250
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
251
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
252
+ esac
253
+ ;;
254
+ stop)
255
+ [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
256
+ if [ "$#" -eq 1 ]; then
257
+ do_stop
258
+ else
259
+ i=`grep $2 $CONFIG`
260
+ dir=`echo $i | cut -d , -f 1`
261
+ do_stop_one $dir
262
+ fi
263
+ case "$?" in
264
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
265
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
266
+ esac
267
+ ;;
268
+ status)
269
+ # TODO Implement.
270
+ log_daemon_msg "Status $DESC" "$NAME"
271
+ if [ "$#" -eq 1 ]; then
272
+ do_status
273
+ else
274
+ i=`grep $2 $CONFIG`
275
+ dir=`echo $i | cut -d , -f 1`
276
+ do_status_one $dir
277
+ fi
278
+ case "$?" in
279
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
280
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
281
+ esac
282
+ ;;
283
+ restart)
284
+ log_daemon_msg "Restarting $DESC" "$NAME"
285
+ if [ "$#" -eq 1 ]; then
286
+ do_restart
287
+ else
288
+ i=`grep $2 $CONFIG`
289
+ dir=`echo $i | cut -d , -f 1`
290
+ do_restart_one $dir
291
+ fi
292
+ case "$?" in
293
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
294
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
295
+ esac
296
+ ;;
297
+ add)
298
+ if [ "$#" -lt 3 ]; then
299
+ echo "Please, specifiy the app's directory and the user that will run it at least."
300
+ echo " Usage: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log"
301
+ echo " config and log are optionals."
302
+ exit 1
303
+ else
304
+ do_add $2 $3 $4 $5
305
+ fi
306
+ case "$?" in
307
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
308
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
309
+ esac
310
+ ;;
311
+ remove)
312
+ if [ "$#" -lt 2 ]; then
313
+ echo "Please, specifiy the app's directory to remove."
314
+ exit 1
315
+ else
316
+ do_remove $2
317
+ fi
318
+ case "$?" in
319
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
320
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
321
+ esac
322
+ ;;
323
+ *)
324
+ echo "Usage:" >&2
325
+ echo " Run the jungle: $SCRIPTNAME {start|stop|status|restart}" >&2
326
+ echo " Add a Puma: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log"
327
+ echo " config and log are optionals."
328
+ echo " Remove a Puma: $SCRIPTNAME remove /path/to/app"
329
+ echo " On a Puma: $SCRIPTNAME {start|stop|status|restart} PUMA-NAME" >&2
330
+ exit 3
331
+ ;;
332
+ esac
333
+ :
@@ -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/pigs/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,13 @@
1
+ #!/usr/bin/env puma
2
+
3
+ directory '<%= current_path %>'
4
+ environment '<%= fetch(:puma_env) %>'
5
+ daemonize true
6
+ pidfile "<%=fetch(:puma_pid)%>"
7
+ state_path "<%=fetch(:puma_state)%>"
8
+ stdout_redirect '<%=fetch(:puma_access_log)%>', '<%=fetch(:puma_error_log)%>', true
9
+ threads <%=fetch(:puma_threads).join(',')%>
10
+ bind "<%=fetch(:puma_bind)%>"
11
+
12
+ workers <%=fetch(:puma_workers)%>
13
+ preload_app!
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ cd $1 && exec bundle exec puma -C config/puma.rb
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano3-puma
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
+ platform: ruby
6
+ authors:
7
+ - Abdelkader Boudih
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-20 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.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ description: Puma integration for Capistrano 3
28
+ email:
29
+ - Terminale@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - capistrano-puma.gemspec
40
+ - capistrano3-puma.gemspec
41
+ - lib/capistrano-puma.rb
42
+ - lib/capistrano/puma.rb
43
+ - lib/capistrano/puma/jungle.rb
44
+ - lib/capistrano/puma/version.rb
45
+ - lib/capistrano/tasks/jungle.cap
46
+ - lib/capistrano/tasks/puma.cap
47
+ - lib/capistrano/templates/puma-deb.erb
48
+ - lib/capistrano/templates/puma-rpm.erb
49
+ - lib/capistrano/templates/puma.rb.erb
50
+ - lib/capistrano/templates/run-puma.erb
51
+ homepage: https://github.com/seuros/capistrano-puma
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.0.3
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Puma integration for Capistrano
75
+ test_files: []
76
+ has_rdoc: