capistrano-unformatt 0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bad8b6136094ae3e1a737a85164a3a9e30bf4a7e
4
+ data.tar.gz: 77931ff9647ffebb5f91cf332bb33fbfc6afb704
5
+ SHA512:
6
+ metadata.gz: 5ecf7c20f5cd9aaf3143b0a8b69d95c3e4559a50543bba14c15cef1310c75f98041ec5cee037ea4bb6fe2ae923a3435524e19eff97c39a64fa03071366ed296a
7
+ data.tar.gz: 16a5f71d02570d23d845ae99fb0e1fe535dc36b0c9b1d72323b55e9516dce044aa2ef24a5b7452d9da03cf79d250a7ed1cba97b8a120562609c168520ce3bac1
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## v0.1.0
2
+
3
+ * Initial release
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 unformatt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Capistrano::Unformatt
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/capistrano/unformatt`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'capistrano-unformatt'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install capistrano-unformatt
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/capistrano-unformatt. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,75 @@
1
+ namespace :deploy do
2
+ namespace :monit do
3
+ desc "Reloads monit service"
4
+ task :reload do
5
+ on roles :app do
6
+ execute "sudo monit reload"
7
+ end
8
+ end
9
+
10
+ desc "Starts applications"
11
+ task :start do
12
+ if ENV['DAEMONS'].present?
13
+ on roles :app do
14
+ ENV['DAEMONS'].split(',').each do |daemon|
15
+ execute "sudo monit start #{fetch(:application)}-#{daemon}"
16
+ end
17
+ end
18
+ else
19
+ execute "sudo monit -g #{fetch(:application)} start all"
20
+ end
21
+ end
22
+
23
+ desc "Stops applications"
24
+ task :stop do
25
+ if ENV['DAEMONS'].present?
26
+ on roles :app do
27
+ ENV['DAEMONS'].split(',').each do |daemon|
28
+ execute "sudo monit stop #{fetch(:application)}-#{daemon}"
29
+ end
30
+ end
31
+ else
32
+ execute "sudo monit -g #{fetch(:application)} stop all"
33
+ end
34
+ end
35
+
36
+ desc "Restarts applications"
37
+ task :restart do
38
+ if ENV['DAEMONS'].present?
39
+ on roles :app do
40
+ ENV['DAEMONS'].split(',').each do |daemon|
41
+ execute "sudo monit restart #{fetch(:application)}-#{daemon}"
42
+ end
43
+ end
44
+ else
45
+ execute "sudo monit -g #{fetch(:application)} restart all"
46
+ end
47
+ end
48
+
49
+ desc "Starts monitoring applications"
50
+ task :monitor do
51
+ if ENV['DAEMONS'].present?
52
+ on roles :app do
53
+ ENV['DAEMONS'].split(',').each do |daemon|
54
+ execute "sudo monit monitor #{fetch(:application)}-#{daemon}"
55
+ end
56
+ end
57
+ else
58
+ execute "sudo monit -g #{fetch(:application)} monitor all"
59
+ end
60
+ end
61
+
62
+ desc "Stops monitoring applications"
63
+ task :unmonitor do
64
+ if ENV['DAEMONS'].present?
65
+ on roles :app do
66
+ ENV['DAEMONS'].split(',').each do |daemon|
67
+ execute "sudo monit unmonitor #{fetch(:application)}-#{daemon}"
68
+ end
69
+ end
70
+ else
71
+ execute "sudo monit -g #{fetch(:application)} unmonitor all"
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,45 @@
1
+ namespace :deploy do
2
+ namespace :nginx do
3
+ desc "Enables site"
4
+ task :enable do
5
+ on roles :web do
6
+ execute "sudo ln -snf #{fetch(:nginx_path)}/sites-available/#{fetch(:application)} #{fetch(:nginx_path)}/sites-enabled/#{fetch(:application)}"
7
+ end
8
+ end
9
+
10
+ desc "Disables site"
11
+ task :disable do
12
+ on roles :web do
13
+ execute "sudo rm #{fetch(:nginx_path)}/sites-enabled/#{fetch(:application)}"
14
+ end
15
+ end
16
+
17
+ desc "Reloads nginx service"
18
+ task :reload do
19
+ on roles :web do
20
+ execute "sudo service nginx reload"
21
+ end
22
+ end
23
+
24
+ desc "Starts nginx"
25
+ task :start do
26
+ on roles :web do
27
+ execute "sudo service nginx start"
28
+ end
29
+ end
30
+
31
+ desc "Stops nginx"
32
+ task :stop do
33
+ on roles :web do
34
+ execute "sudo service nginx stop"
35
+ end
36
+ end
37
+
38
+ desc "Restarts nginx"
39
+ task :restart do
40
+ on roles :web do
41
+ execute "sudo service nginx restart"
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,13 @@
1
+ namespace :deploy do
2
+ namespace :rails do
3
+ task :seed do
4
+ on roles :app do
5
+ within current_path do
6
+ with rails_env: "#{fetch(:rails_env)}" do
7
+ execute :rake, "db:seed"
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,64 @@
1
+ append :templating_paths, "capistrano/unformatt/vendor/templates"
2
+
3
+ namespace :deploy do
4
+ desc "Creates project files."
5
+ task :install do
6
+ on roles :app do
7
+ # yaml files
8
+ execute "mkdir -p #{shared_path}/{config,tmp}"
9
+
10
+ fetch(:setup_yamls, []).each do |yaml|
11
+ template "#{yaml}.yml.erb", "#{shared_path}/config/#{yaml}.yml"
12
+ end
13
+
14
+ fetch(:setup_daemons, []).each do |daemon|
15
+ if daemon[:config] == true
16
+ template "#{daemon[:name]}.rb.erb", "#{shared_path}/config/#{daemon[:name]}.rb", 0644
17
+ end
18
+
19
+ template "#{daemon[:name]}.daemon.erb", "#{shared_path}/tmp/#{daemon[:name]}.daemon", 0755
20
+ execute "sudo mv #{shared_path}/tmp/#{daemon[:name]}.daemon #{fetch(:daemons_path)}/#{fetch(:application)}-#{daemon[:name]}"
21
+
22
+ template "#{daemon[:name]}.monit.erb", "#{shared_path}/tmp/#{daemon[:name]}.monit", 0644
23
+ execute "sudo mv #{shared_path}/tmp/#{daemon[:name]}.monit #{fetch(:monit_scripts_path)}/#{fetch(:application)}-#{daemon[:name]}"
24
+ end
25
+
26
+ execute "sudo service monit reload"
27
+ end
28
+
29
+ if fetch(:setup_nginx, false) == true
30
+ on roles :web do
31
+ execute "mkdir -p #{fetch(:deploy_to)}"
32
+ template "nginx.conf.erb", "#{shared_path}/tmp/nginx.conf", 0644
33
+ execute "sudo mv #{shared_path}/tmp/nginx.conf #{fetch(:nginx_path)}/sites-available/#{fetch(:application)}"
34
+ execute "sudo ln -snf #{fetch(:nginx_path)}/sites-available/#{fetch(:application)} #{fetch(:nginx_path)}/sites-enabled/#{fetch(:application)}"
35
+ execute "sudo service nginx reload"
36
+ end
37
+ end
38
+ end
39
+
40
+ desc "Removes all project files."
41
+ task :uninstall do
42
+ on roles :all do
43
+ fetch(:setup_daemons, []).each do |daemon|
44
+ execute "sudo monit stop #{fetch(:application)}-#{daemon[:name]}", raise_on_non_zero_exit: false
45
+ execute "sudo rm -f /etc/init.d/#{fetch(:application)}-#{daemon[:name]}"
46
+ execute "sudo rm -f /etc/monit/conf.d/#{fetch(:application)}-#{daemon[:name]}"
47
+ end
48
+
49
+ if fetch(:setup_daemons, []).any?
50
+ execute "sudo service monit reload"
51
+ end
52
+
53
+ if fetch(:setup_nginx, false) == true
54
+ execute "sudo rm -f /etc/nginx/sites_available/#{fetch(:application)}"
55
+ execute "sudo rm -f /etc/nginx/sites_enabled/#{fetch(:application)}"
56
+ execute "sudo service nginx reload"
57
+ end
58
+
59
+ if fetch(:erase_deploy_folder_on_uninstall, false) == true
60
+ execute "rm -rf #{fetch(:deploy_to)/*}"
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,31 @@
1
+ namespace :deploy do
2
+ namespace :sidekiq do
3
+ desc "Starts sidekiq"
4
+ task :start do
5
+ on roles :app do
6
+ execute "#{daemons_path}/#{fetch(:application)}-sidekiq start"
7
+ end
8
+ end
9
+
10
+ desc "Stops sidekiq"
11
+ task :stop do
12
+ on roles :app do
13
+ execute "#{daemons_path}/#{fetch(:application)}-sidekiq stop"
14
+ end
15
+ end
16
+
17
+ desc "Restarts sidekiq"
18
+ task :restart do
19
+ on roles :app do
20
+ execute "#{daemons_path}/#{fetch(:application)}-sidekiq restart"
21
+ end
22
+ end
23
+
24
+ desc "Rejects new sidekiq jobs"
25
+ task :reject_jobs do
26
+ on roles :app do
27
+ execute "#{daemons_path}/#{fetch(:application)}-sidekiq reject_jobs"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ namespace :deploy do
2
+ namespace :sunspot do
3
+ desc "Starts sunspot"
4
+ task :start do
5
+ on roles :app do
6
+ execute "#{daemons_path}/#{fetch(:application)}-sunspot start"
7
+ end
8
+ end
9
+
10
+ desc "Stops sunspot"
11
+ task :stop do
12
+ on roles :app do
13
+ execute "#{daemons_path}/#{fetch(:application)}-sunspot stop"
14
+ end
15
+ end
16
+
17
+ desc "Starts sunspot"
18
+ task :restart do
19
+ on roles :app do
20
+ execute "#{daemons_path}/#{fetch(:application)}-sunspot restart"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ namespace :deploy do
2
+ namespace :unicorn do
3
+ desc "Starts unicorn"
4
+ task :start do
5
+ on roles :app do
6
+ execute "#{daemons_path}/#{fetch(:application)}-unicorn start"
7
+ end
8
+ end
9
+
10
+ desc "Stops unicorn"
11
+ task :stop do
12
+ on roles :app do
13
+ execute "#{daemons_path}/#{fetch(:application)}-unicorn stop"
14
+ end
15
+ end
16
+
17
+ desc "Starts unicorn"
18
+ task :restart do
19
+ on roles :app do
20
+ execute "#{daemons_path}/#{fetch(:application)}-unicorn restart"
21
+ end
22
+ end
23
+
24
+ desc "Reloads unicorn"
25
+ task :reload do
26
+ on roles :app do
27
+ execute "#{daemons_path}/#{fetch(:application)}-unicorn reload"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/rake.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/nginx.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/rails.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/setup.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/sidekiq.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/sunspot.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/unicorn.rake", __FILE__)
@@ -0,0 +1,8 @@
1
+ require 'capistrano/capistrano_plugin_template'
2
+ require "capistrano/unformatt/monit"
3
+ require "capistrano/unformatt/nginx"
4
+ require "capistrano/unformatt/rails"
5
+ require "capistrano/unformatt/setup"
6
+ require "capistrano/unformatt/sidekiq"
7
+ require "capistrano/unformatt/sunspot"
8
+ require "capistrano/unformatt/unicorn"
@@ -0,0 +1,73 @@
1
+ upstream <%=fetch(:application)%> {
2
+ server <%="#{fetch(:app_server_host)}:#{fetch(:app_server_port)}"%>;
3
+ }
4
+
5
+ <%- if fetch(:nginx_use_ssl) -%>
6
+ server {
7
+ listen 80;
8
+ server_name <%=fetch(:nginx_server_names)%>;
9
+ rewrite ^ https://$server_name$request_uri? permanent;
10
+ }
11
+ <%- end -%>
12
+
13
+ server {
14
+ <%- if fetch(:nginx_use_ssl) -%>
15
+ listen 443;
16
+ ssl on;
17
+ ssl_certificate <%=fetch(:nginx_ssl_certificate)%>;
18
+ ssl_certificate_key <%=fetch(:nginx_ssl_private_key)%>;
19
+ ssl_session_cache shared:SSL:10m;
20
+ ssl_session_timeout 5m;
21
+ ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
22
+ ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
23
+ ssl_prefer_server_ciphers on;
24
+ ssl_dhparam /etc/ssl/private/dhparams.pem;
25
+ <%- end -%>
26
+
27
+ server_name <%=fetch(:nginx_server_names)%>;
28
+ root <%=current_path%>/public;
29
+ access_log <%=shared_path%>/log/nginx-access.log;
30
+ error_log <%=shared_path%>/log/nginx-error.log;
31
+ rewrite_log on;
32
+
33
+ client_max_body_size 4G;
34
+ keepalive_timeout 5;
35
+
36
+ if (-f $document_root/public/maintenance.html) {
37
+ rewrite ^(.*)$ /public/maintenance.html;
38
+ break;
39
+ }
40
+
41
+ location ~ ^/(assets)/ {
42
+ root <%=current_path%>/public;
43
+ gzip_static on;
44
+ expires max;
45
+ add_header Cache-Control public;
46
+ break;
47
+ }
48
+
49
+ location / {
50
+ try_files $uri/index.html $uri.html $uri @<%=fetch(:application)%>;
51
+
52
+ error_page 404 /404.html;
53
+ error_page 422 /422.html;
54
+ error_page 500 502 503 504 /500.html;
55
+ error_page 403 /403.html;
56
+ break;
57
+ }
58
+
59
+ location @<%=fetch(:application)%> {
60
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
61
+ proxy_set_header Host $http_host;
62
+ <%- if fetch(:nginx_use_ssl) -%>
63
+ proxy_set_header X-Forwarded-Proto https;
64
+ <%- end -%>
65
+ proxy_headers_hash_bucket_size 1024;
66
+ proxy_headers_hash_max_size 512;
67
+ proxy_read_timeout <%=fetch(:nginx_read_timeout)%>;
68
+ proxy_redirect off;
69
+ proxy_pass http://<%=fetch(:application)%>;
70
+ include proxy_params;
71
+ break;
72
+ }
73
+ }
@@ -0,0 +1,67 @@
1
+ #!/bin/bash
2
+
3
+ # <%= "Start or stop #{fetch(:application)}-puma" %>
4
+ #
5
+ # Matias Hick <me@unformatt.com.ar>
6
+
7
+ ### BEGIN INIT INFO
8
+ # Provides: <%= "#{fetch(:application)}-puma" %>
9
+ # Required-Start: $local_fs $remote_fs $syslog $network
10
+ # Required-Stop: $local_fs $remote_fs $syslog $network
11
+ # Should-Start:
12
+ # Should-Stop:
13
+ # Default-Start: 2 3 4 5
14
+ # Default-Stop: 0 1 6
15
+ # Short-Description: <%= "Starts #{fetch(:application)}-puma" %>
16
+ # Description: <%= "Launches #{fetch(:application)}-puma" %>
17
+ ### END INIT INFO
18
+
19
+ PATH=/home/maintainer/.rbenv/shims:/home/maintainer/.rbenv/bin:$PATH
20
+ PIDFILE=<%= "#{shared_path}/pids/puma.pid" %>
21
+ export RAILS_ENV=production
22
+
23
+ getPID() {
24
+ if [ ! -z `cat $PIDFILE 2> /dev/null` ]; then
25
+ if [[ ! -z $(ps -ef | grep -w `cat $PIDFILE` | grep -v grep) ]]; then
26
+ echo `cat $PIDFILE 2> /dev/null`
27
+ fi
28
+ fi
29
+ }
30
+
31
+ case "$1" in
32
+ start)
33
+ echo -ne "<%= "Starting #{fetch(:application)}-puma..." %>"
34
+
35
+ if [ -z "$(getPID)" ]; then
36
+ cd <%=current_path%>
37
+ bundle exec puma -q -d -C <%= "#{shared_path}/config/puma.rb" %>
38
+
39
+ echo "started!"
40
+ else
41
+ echo "is already running!"
42
+ fi
43
+ ;;
44
+
45
+ stop)
46
+ echo -ne "<%= "Stopping #{fetch(:application)}-puma..." %>"
47
+
48
+ if [ -z "$(getPID)" ]; then
49
+ echo "is not running!"
50
+ else
51
+ cd <%=current_path%>
52
+ bundle exec pumactl -S <%= "#{shared_path}/pids/puma.state" %> stop
53
+
54
+ echo "stopped!"
55
+ fi
56
+ ;;
57
+
58
+ restart)
59
+ $0 stop
60
+ sleep 3
61
+ $0 start
62
+ ;;
63
+
64
+ *)
65
+ echo "usage: $0 {start|stop|restart}"
66
+ esac
67
+ exit 0
@@ -0,0 +1,6 @@
1
+ check process <%="#{fetch(:application)}-puma"%>
2
+ with pidfile <%="#{shared_path}/pids/puma.pid"%>
3
+ group <%=fetch(:application)%>
4
+ start program = "<%="#{fetch(:daemons_path)}/#{fetch(:application)}-puma start"%>"
5
+ as uid <%=fetch(:monit_user)%> and gid <%=fetch(:monit_group)%>
6
+ stop program = "<%="#{fetch(:daemons_path)}/#{fetch(:application)}-puma stop"%>"
@@ -0,0 +1,21 @@
1
+ directory "<%=current_path%>"
2
+ environment "production"
3
+ daemonize true
4
+
5
+ pidfile '<%="#{shared_path}/pids/puma.pid"%>'
6
+ state_path '<%="#{shared_path}/pids/puma.state"%>'
7
+ stdout_redirect "<%="#{shared_path}/log/puma.stdout.log"%>", "<%="#{shared_path}/log/puma.stderr.log"%>", true
8
+
9
+ threads 0, 8
10
+ bind "<%="tcp://#{fetch(:app_server_host)}:#{fetch(:app_server_port)}"%>"
11
+ workers 4
12
+
13
+ preload_app!
14
+
15
+ on_worker_boot do
16
+ ActiveSupport.on_load(:active_record) do
17
+ ActiveRecord::Base.establish_connection
18
+ end
19
+ end
20
+
21
+
@@ -0,0 +1,78 @@
1
+ #!/bin/bash
2
+
3
+ # <%= "Start or stop #{fetch(:application)}-sidekiq" %>
4
+ #
5
+ # Matias Hick <me@unformatt.com.ar>
6
+
7
+ ### BEGIN INIT INFO
8
+ # Provides: <%= "#{fetch(:application)}-sidekiq" %>
9
+ # Required-Start: $local_fs $remote_fs $syslog $network
10
+ # Required-Stop: $local_fs $remote_fs $syslog $network
11
+ # Should-Start:
12
+ # Should-Stop:
13
+ # Default-Start: 2 3 4 5
14
+ # Default-Stop: 0 1 6
15
+ # Short-Description: <%= "Starts #{fetch(:application)}-sidekiq" %>
16
+ # Description: <%= "Launches #{fetch(:application)}-sidekiq" %>
17
+ ### END INIT INFO
18
+
19
+ PATH=/home/maintainer/.rbenv/shims:/home/maintainer/.rbenv/bin:$PATH
20
+ PIDFILE=<%= "#{shared_path}/pids/sidekiq.pid" %>
21
+ export RAILS_ENV=production
22
+
23
+ getPID() {
24
+ if [ ! -z `cat $PIDFILE 2> /dev/null` ]; then
25
+ if [[ ! -z $(ps -ef | grep -w `cat $PIDFILE` | grep -v grep) ]]; then
26
+ echo `cat $PIDFILE 2> /dev/null`
27
+ fi
28
+ fi
29
+ }
30
+
31
+ case "$1" in
32
+ start)
33
+ echo -ne "<%= "Starting #{fetch(:application)}-sidekiq..." %>"
34
+
35
+ if [ -z "$(getPID)" ]; then
36
+ cd <%=current_path%>
37
+ bundle exec sidekiq -d -v -P $PIDFILE -e $RAILS_ENV -L <%= "#{shared_path}/log/sidekiq.log" %>
38
+
39
+ echo "started!"
40
+ else
41
+ echo "is already running!"
42
+ fi
43
+ ;;
44
+
45
+ stop)
46
+ echo -ne "<%= "Stopping #{fetch(:application)}-sidekiq..." %>"
47
+
48
+ if [ -z "$(getPID)" ]; then
49
+ echo "is not running!"
50
+ else
51
+ kill -TERM $(getPID) &> /dev/null
52
+
53
+ echo "stopped!"
54
+ fi
55
+ ;;
56
+
57
+ restart)
58
+ $0 stop
59
+ sleep 3
60
+ $0 start
61
+ ;;
62
+
63
+ reject_jobs)
64
+ echo -ne "<%= "Rejecting new jobs #{fetch(:application)}-sidekiq..." %>"
65
+
66
+ if [ -z "$(getPID)" ]; then
67
+ echo "is not running!"
68
+ else
69
+ kill -USR1 $(getPID) &> /dev/null
70
+
71
+ echo "new jobs will be rejected"
72
+ fi
73
+ ;;
74
+
75
+ *)
76
+ echo "usage: $0 {start|stop|restart|reject_jobs}"
77
+ esac
78
+ exit 0
@@ -0,0 +1,6 @@
1
+ check process <%="#{fetch(:application)}-sidekiq"%>
2
+ with pidfile <%="#{shared_path}/pids/sidekiq.pid"%>
3
+ group <%=fetch(:application)%>
4
+ start program = "<%="#{fetch(:daemons_path)}/#{fetch(:application)}-sidekiq start"%>"
5
+ as uid <%=fetch(:monit_user)%> and gid <%=fetch(:monit_group)%>
6
+ stop program = "<%="#{fetch(:daemons_path)}/#{fetch(:application)}-sidekiq stop"%>"
@@ -0,0 +1,76 @@
1
+ #!/bin/bash
2
+
3
+ # <%= "Start or stop #{fetch(:application)}-sunspot" %>
4
+ #
5
+ # Matias Hick <me@unformatt.com.ar>
6
+
7
+ ### BEGIN INIT INFO
8
+ # Provides: <%= "#{fetch(:application)}-sunspot" %>
9
+ # Required-Start: $local_fs $remote_fs $syslog $network
10
+ # Required-Stop: $local_fs $remote_fs $syslog $network
11
+ # Should-Start:
12
+ # Should-Stop:
13
+ # Default-Start: 2 3 4 5
14
+ # Default-Stop: 0 1 6
15
+ # Short-Description: <%= "Starts #{fetch(:application)}-sunspot" %>
16
+ # Description: <%= "Launches #{fetch(:application)}-sunspot" %>
17
+ ### END INIT INFO
18
+
19
+ PATH=/home/maintainer/.rbenv/shims:/home/maintainer/.rbenv/bin:$PATH
20
+ PIDFILE=<%= "#{shared_path}/pids/sunspot-solr.pid" %>
21
+ export RAILS_ENV=production
22
+
23
+ getPID() {
24
+ if [ ! -z `cat $PIDFILE 2> /dev/null` ]; then
25
+ if [[ ! -z $(ps -ef | grep -w `cat $PIDFILE` | grep -v grep) ]]; then
26
+ echo `cat $PIDFILE 2> /dev/null`
27
+ fi
28
+ fi
29
+ }
30
+
31
+ case "$1" in
32
+ start)
33
+ echo -ne "<%= "Starting #{fetch(:application)}-sunspot..." %>"
34
+
35
+ if [ -z "$(getPID)" ]; then
36
+ cd <%=current_path%>
37
+ bundle exec rake sunspot:solr:start
38
+
39
+ echo "started!"
40
+ else
41
+ echo "is already running!"
42
+ fi
43
+ ;;
44
+
45
+ stop)
46
+ echo -ne "<%= "Stopping #{fetch(:application)}-sunspot..." %>"
47
+
48
+ if [ -z "$(getPID)" ]; then
49
+ echo "is not running!"
50
+ else
51
+ cd <%=current_path%>
52
+ bundle exec rake sunspot:solr:stop
53
+
54
+ echo "stopped!"
55
+ fi
56
+ ;;
57
+
58
+ reindex)
59
+ echo -ne "<%= "Reindexing #{fetch(:application)}-sunspot..." %>"
60
+ if [ -z "$(getPID)" ]; then
61
+ echo "is not running!"
62
+ else
63
+ cd <%=current_path%>
64
+ bundle exec rake sunspot:solr:reindex
65
+ fi
66
+ ;;
67
+
68
+ restart)
69
+ $0 stop
70
+ $0 start
71
+ ;;
72
+
73
+ *)
74
+ echo "usage: $0 {start|stop|restart|reindex}"
75
+ esac
76
+ exit 0
@@ -0,0 +1,6 @@
1
+ check process <%="#{fetch(:application)}-sunspot"%>
2
+ with pidfile <%="#{shared_path}/pids/sunspot-solr-production.pid"%>
3
+ group <%=fetch(:application)%>
4
+ start program = "<%="#{fetch(:daemons_path)}/#{fetch(:application)}-sunspot start"%>"
5
+ as uid <%=fetch(:monit_user)%> and gid <%=fetch(:monit_group)%>
6
+ stop program = "<%="#{fetch(:daemons_path)}/#{fetch(:application)}-sunspot stop"%>"
@@ -0,0 +1,88 @@
1
+ #!/bin/bash
2
+
3
+ # <%= "Start or stop #{fetch(:application)}-unicorn" %>
4
+ #
5
+ # Matias Hick <me@unformatt.com.ar>
6
+
7
+ ### BEGIN INIT INFO
8
+ # Provides: <%= "#{fetch(:application)}-unicorn" %>
9
+ # Required-Start: $local_fs $remote_fs $syslog $network
10
+ # Required-Stop: $local_fs $remote_fs $syslog $network
11
+ # Should-Start:
12
+ # Should-Stop:
13
+ # Default-Start: 2 3 4 5
14
+ # Default-Stop: 0 1 6
15
+ # Short-Description: <%= "Starts #{fetch(:application)}-unicorn" %>
16
+ # Description: <%= "Launches #{fetch(:application)}-unicorn" %>
17
+ ### END INIT INFO
18
+
19
+ PATH=/home/maintainer/.rbenv/shims:/home/maintainer/.rbenv/bin:$PATH
20
+ PIDFILE=<%= "#{shared_path}/pids/unicorn.pid" %>
21
+ export RAILS_ENV=production
22
+
23
+ getPID() {
24
+ if [ ! -z `cat $PIDFILE 2> /dev/null` ]; then
25
+ if [[ ! -z $(ps -ef | grep -w `cat $PIDFILE` | grep -v grep) ]]; then
26
+ echo `cat $PIDFILE 2> /dev/null`
27
+ fi
28
+ fi
29
+ }
30
+
31
+ case "$1" in
32
+ start)
33
+ echo -ne "<%= "Starting #{fetch(:application)}-unicorn..." %>"
34
+
35
+ if [ -z "$(getPID)" ]; then
36
+ cd <%=current_path%>
37
+ bundle exec unicorn -c <%= "#{shared_path}/config/unicorn.rb" %> -D
38
+
39
+ echo "started!"
40
+ else
41
+ echo "is already running!"
42
+ fi
43
+ ;;
44
+
45
+ stop)
46
+ echo -ne "<%= "Stopping #{fetch(:application)}-unicorn..." %>"
47
+
48
+ if [ -z "$(getPID)" ]; then
49
+ echo "is not running!"
50
+ else
51
+ kill -INT $(getPID) &> /dev/null
52
+
53
+ echo "stopped!"
54
+ fi
55
+ ;;
56
+
57
+ graceful_stop)
58
+ if [ -z "$(getPID)" ]; then
59
+ echo "<%= "#{fetch(:application)}-unicorn is not running!" %>"
60
+ else
61
+ kill -QUIT $(getPID) &> /dev/null
62
+
63
+ echo "<%= "#{fetch(:application)}-unicorn will stop after current request finishes." %>"
64
+ fi
65
+ ;;
66
+
67
+ restart)
68
+ $0 stop
69
+ sleep 3
70
+ $0 start
71
+ ;;
72
+
73
+ reload)
74
+ echo -ne "<%= "Reloading #{fetch(:application)}-unicorn..." %>"
75
+
76
+ if [ -z "$(getPID)" ]; then
77
+ echo "is not running!"
78
+ else
79
+ kill -USR2 $(getPID) &> /dev/null
80
+
81
+ echo "reloaded!"
82
+ fi
83
+ ;;
84
+
85
+ *)
86
+ echo "usage: $0 {start|stop|graceful_stop|restart|reload}"
87
+ esac
88
+ exit 0
@@ -0,0 +1,6 @@
1
+ check process <%="#{fetch(:application)}-unicorn"%>
2
+ with pidfile <%="#{shared_path}/pids/unicorn.pid"%>
3
+ group <%=fetch(:application)%>
4
+ start program = "<%="#{fetch(:daemons_path)}/#{fetch(:application)}-unicorn start"%>"
5
+ as uid <%=fetch(:monit_user)%> and gid <%=fetch(:monit_group)%>
6
+ stop program = "<%="#{fetch(:daemons_path)}/#{fetch(:application)}-unicorn stop"%>"
@@ -0,0 +1,39 @@
1
+ ENV['RAILS_ENV'] = 'production'
2
+ worker_processes 4
3
+
4
+ listen "<%="#{fetch(:app_server_host)}:#{fetch(:app_server_port)}"%>", :backlog => 2048
5
+
6
+ timeout 60
7
+
8
+ working_directory "<%=current_path%>"
9
+
10
+ pid "<%="#{shared_path}/pids/unicorn.pid"%>"
11
+ stderr_path "<%="#{shared_path}/log/unicorn.stderr.log"%>"
12
+ stdout_path "<%="#{shared_path}/log/unicorn.stdout.log"%>"
13
+
14
+ preload_app true
15
+ GC.respond_to?(:copy_on_write_friendly=) and
16
+ GC.copy_on_write_friendly = true
17
+
18
+ before_fork do |server, worker|
19
+ # Close connections on the master process if ActiveRecord is loaded
20
+ if defined?(ActiveRecord::Base)
21
+ ActiveRecord::Base.connection.disconnect!
22
+ end
23
+
24
+ old_pid = "#{server.config[:pid]}.oldbin"
25
+
26
+ if File.exists?(old_pid) && server.pid != old_pid
27
+ begin
28
+ sig = (worker.nr + 1) >= server.worker_processes ? :TERM : :TTOU
29
+ Process.kill(sig, File.read(old_pid).to_i)
30
+ rescue Errno::ENOENT, Errno::ESRCH
31
+ # It’s already gone
32
+ end
33
+ end
34
+ end
35
+
36
+ after_fork do |server, worker|
37
+ defined?(ActiveRecord::Base) and
38
+ ActiveRecord::Base.establish_connection
39
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-unformatt
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - unformatt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-21 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.1.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.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: capistrano-template
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.7
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.7
41
+ description: Custom recipes for Unformatt projects
42
+ email:
43
+ - unformatt@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - CHANGELOG.md
49
+ - LICENSE.md
50
+ - README.md
51
+ - lib/capistrano/tasks/monit.rake
52
+ - lib/capistrano/tasks/nginx.rake
53
+ - lib/capistrano/tasks/rails.rake
54
+ - lib/capistrano/tasks/setup.rake
55
+ - lib/capistrano/tasks/sidekiq.rake
56
+ - lib/capistrano/tasks/sunspot.rake
57
+ - lib/capistrano/tasks/unicorn.rake
58
+ - lib/capistrano/unformatt.rb
59
+ - lib/capistrano/unformatt/monit.rb
60
+ - lib/capistrano/unformatt/nginx.rb
61
+ - lib/capistrano/unformatt/rails.rb
62
+ - lib/capistrano/unformatt/setup.rb
63
+ - lib/capistrano/unformatt/sidekiq.rb
64
+ - lib/capistrano/unformatt/sunspot.rb
65
+ - lib/capistrano/unformatt/unicorn.rb
66
+ - vendor/templates/nginx.conf.erb
67
+ - vendor/templates/puma.daemon.erb
68
+ - vendor/templates/puma.monit.erb
69
+ - vendor/templates/puma.rb.erb
70
+ - vendor/templates/sidekiq.daemon.erb
71
+ - vendor/templates/sidekiq.monit.erb
72
+ - vendor/templates/sunspot.daemon.erb
73
+ - vendor/templates/sunspot.monit.erb
74
+ - vendor/templates/unicorn.daemon.erb
75
+ - vendor/templates/unicorn.monit.erb
76
+ - vendor/templates/unicorn.rb.erb
77
+ homepage: https://github.com/unformattmh/capistrano-unformatt
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.5.2
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Custom recipes for Unformatt projects
101
+ test_files: []