immosquare-capistrano 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd4a36233e060600fceaf3284d69e888a1cc2e878f0f2989e2ee84133b109dbc
4
- data.tar.gz: 86d11c5ff55f124e30e032983c87473beb5cde9026f89870b1bd7a812d2583be
3
+ metadata.gz: d63f243f98fe9e7c78dbaa6907959df6ca0c8021cf35cda1f35de86743cbeb7b
4
+ data.tar.gz: 47f3e09254bb0aa1327bc23d9a24a01dbbc51276b1dd5ad15a7ee4478239a333
5
5
  SHA512:
6
- metadata.gz: 14f0e82c609fc01e275979e552bb43ff5c59c87162cb036968b53796e44c3197f69f41f0217545108b3fbf7923e9a05715e09d94e7715338cdf5832ebffd9df7
7
- data.tar.gz: 391981483ca9e86340f7386805b46058e3ac06feafd20a63db3dc8dc4d9649a644288e68df52fd87d999acaa640bf68125adc804fbbb60ecb76d22fda9af3659
6
+ metadata.gz: 376f46c4d8596c3d8844ad55f81bf987786610a7bb71ea1cfbebae15071ff8d644a1a4767616ba6c79f61af02a666c9ac471d9519a6c845bbba604c490c5c460
7
+ data.tar.gz: e0f29fa182a215f634a10a9148148e3434d7978850e4e61adf862686acbca79aee852d080108bfcd95ae4fd76385386b1ba5ce46a481b87758d1a63e747ce275
@@ -1,5 +1,7 @@
1
1
  namespace :load do
2
2
  task :defaults do
3
- set_if_empty :solid_queue_service_unit_name, -> { "solid_queue_#{fetch(:application)}_puma_#{fetch(:stage)}" }
3
+ set_if_empty :puma_service_unit_name, -> { "puma_#{fetch(:application)}_#{fetch(:stage)}" }
4
+ set_if_empty :sidekiq_service_unit_name, -> { "sidekiq_#{fetch(:application)}_#{fetch(:stage)}" }
5
+ set_if_empty :solid_queue_service_unit_name, -> { "solid_queue_#{fetch(:application)}_#{fetch(:stage)}" }
4
6
  end
5
7
  end
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
- module SolidQueue
2
+ module Immosquare
3
3
  module Helpers
4
4
  ##============================================================##
5
5
  ## Get the path to bundle command
@@ -12,12 +12,12 @@ module Capistrano
12
12
  "#{File.dirname(__FILE__)}/templates/#{service}.service.erb"
13
13
  end
14
14
 
15
- def self.service_name
16
- "#{fetch(:solid_queue_service_unit_name)}.service"
15
+ def self.service_name(service)
16
+ "#{fetch(:"#{service}_service_unit_name")}.service"
17
17
  end
18
18
 
19
- def self.result_path
20
- "#{fetch(:tmp_dir)}/#{service_name}"
19
+ def self.result_path(service)
20
+ "#{fetch(:tmp_dir)}/#{service_name(service)}"
21
21
  end
22
22
  end
23
23
  end
@@ -0,0 +1,7 @@
1
+ require_relative "defaults"
2
+ require_relative "helpers"
3
+
4
+ load File.expand_path("tasks/puma.rake", __dir__)
5
+
6
+ # puma hooks
7
+ after "deploy:finished", "puma:smart_restart"
@@ -0,0 +1,9 @@
1
+ require_relative "defaults"
2
+ require_relative "helpers"
3
+
4
+ load File.expand_path("tasks/sidekiq.rake", __dir__)
5
+
6
+ # Sidekiq hooks
7
+ after "deploy:starting", "sidekiq:stop"
8
+ after "deploy:published", "sidekiq:start"
9
+ after "deploy:failed", "sidekiq:restart"
@@ -0,0 +1,101 @@
1
+
2
+ namespace :puma do
3
+ ##============================================================##
4
+ ## Install puma service
5
+ ##============================================================##
6
+ desc "Install puma service"
7
+ task :install do
8
+ on roles(:app) do
9
+ template_path = File.read(Capistrano::Immosquare::Helpers.template_path("puma"))
10
+ result = ERB.new(template_path).result(binding)
11
+ result_path = Capistrano::Immosquare::Helpers.result_path("puma")
12
+ service_name = Capistrano::Immosquare::Helpers.service_name("puma")
13
+
14
+ ##============================================================##
15
+ ## Upload the service file to the server
16
+ ##============================================================##
17
+ upload!(StringIO.new(result), result_path)
18
+
19
+ ##============================================================##
20
+ ## Move the service file to the systemd directory
21
+ ##============================================================##
22
+ sudo "mv #{result_path} /etc/systemd/system/#{service_name}"
23
+
24
+ ##============================================================##
25
+ ## Reload the systemd daemon and quiet the service
26
+ ##============================================================##
27
+ sudo "systemctl daemon-reload"
28
+ sudo "systemctl enable #{service_name}"
29
+ end
30
+ end
31
+
32
+ ##============================================================##
33
+ ## Uninstall puma service
34
+ ##============================================================##
35
+ desc "Uninstall puma service"
36
+ task :uninstall do
37
+ on roles(:app) do
38
+ service_name = Capistrano::Immosquare::Helpers.service_name("puma")
39
+
40
+ if test("systemctl list-units --full -all | grep -Fq '#{service_name}'")
41
+ sudo("systemctl stop #{service_name}")
42
+ sudo("systemctl disable #{service_name}")
43
+ sudo("rm -f /etc/systemd/system/#{service_name}")
44
+ sudo("systemctl daemon-reload")
45
+ else
46
+ info("Service #{service_name} does not exist and does not need to be disabled.")
47
+ end
48
+ end
49
+ end
50
+
51
+
52
+ ##============================================================##
53
+ ## Start puma
54
+ ##============================================================##
55
+ desc "Start puma"
56
+ task :start do
57
+ on roles(:app) do
58
+ sudo "systemctl start #{Capistrano::Immosquare::Helpers.service_name("puma")}"
59
+ end
60
+ end
61
+
62
+ ##============================================================##
63
+ ## Stop puma (force immediate termination)
64
+ ##============================================================##
65
+ desc "Stop puma (force immediate termination)"
66
+ task :stop do
67
+ on roles(:app) do
68
+ sudo "systemctl stop #{Capistrano::Immosquare::Helpers.service_name("puma")}"
69
+ end
70
+ end
71
+
72
+ ##============================================================##
73
+ ## Restart puma
74
+ ##============================================================##
75
+ desc "Restart puma"
76
+ task :restart do
77
+ on roles(:app) do
78
+ sudo "systemctl restart #{Capistrano::Immosquare::Helpers.service_name("puma")}"
79
+ end
80
+ end
81
+
82
+ ##============================================================##
83
+ ## Reload puma
84
+ ##============================================================##
85
+ desc "Roload puma"
86
+ task :reload do
87
+ on roles(:app) do
88
+ service_ok = execute("systemctl status #{Capistrano::Immosquare::Helpers.service_name("puma")} > /dev/null", :raise_on_non_zero_exit => false)
89
+ sudo "systemctl #{service_ok ? "reload" : "restart"} #{Capistrano::Immosquare::Helpers.service_name("puma")}"
90
+ end
91
+ end
92
+
93
+
94
+ ##============================================================##
95
+ ## Smart restart puma (with phased restart if enabled)
96
+ ##============================================================##
97
+ desc "Smart restart puma (with phased restart if enabled)"
98
+ task :smart_restart do
99
+ invoke fetch(:puma_phased_restart) ? "puma:reload" : "puma:restart"
100
+ end
101
+ end
@@ -0,0 +1,81 @@
1
+
2
+ namespace :sidekiq do
3
+ ##============================================================##
4
+ ## Install Sidekiq service
5
+ ##============================================================##
6
+ desc "Install Sidekiq service"
7
+ task :install do
8
+ on roles(:app) do
9
+ template_path = File.read(Capistrano::Immosquare::Helpers.template_path("sidekiq"))
10
+ result = ERB.new(template_path).result(binding)
11
+ result_path = Capistrano::Immosquare::Helpers.result_path("sidekiq")
12
+ service_name = Capistrano::Immosquare::Helpers.service_name("sidekiq")
13
+
14
+ ##============================================================##
15
+ ## Upload the service file to the server
16
+ ##============================================================##
17
+ upload!(StringIO.new(result), result_path)
18
+
19
+ ##============================================================##
20
+ ## Move the service file to the systemd directory
21
+ ##============================================================##
22
+ sudo "mv #{result_path} /etc/systemd/system/#{service_name}"
23
+
24
+ ##============================================================##
25
+ ## Reload the systemd daemon and quiet the service
26
+ ##============================================================##
27
+ sudo "systemctl daemon-reload"
28
+ sudo "systemctl enable #{service_name}"
29
+ end
30
+ end
31
+
32
+ ##============================================================##
33
+ ## Uninstall Sidekiq service
34
+ ##============================================================##
35
+ desc "Uninstall Sidekiq service"
36
+ task :uninstall do
37
+ on roles(:app) do
38
+ service_name = Capistrano::Immosquare::Helpers.service_name("sidekiq")
39
+
40
+ if test("systemctl list-units --full -all | grep -Fq '#{service_name}'")
41
+ sudo("systemctl stop #{service_name}")
42
+ sudo("systemctl disable #{service_name}")
43
+ sudo("rm -f /etc/systemd/system/#{service_name}")
44
+ sudo("systemctl daemon-reload")
45
+ else
46
+ info("Service #{service_name} does not exist and does not need to be disabled.")
47
+ end
48
+ end
49
+ end
50
+
51
+
52
+ ##============================================================##
53
+ ## Start sidekiq
54
+ ##============================================================##
55
+ desc "Start sidekiq"
56
+ task :start do
57
+ on roles(:app) do
58
+ sudo "systemctl start #{Capistrano::Immosquare::Helpers.service_name("sidekiq")}"
59
+ end
60
+ end
61
+
62
+ ##============================================================##
63
+ ## Stop sidekiq (force immediate termination)
64
+ ##============================================================##
65
+ desc "Stop sidekiq (force immediate termination)"
66
+ task :stop do
67
+ on roles(:app) do
68
+ sudo "systemctl stop #{Capistrano::Immosquare::Helpers.service_name("sidekiq")}"
69
+ end
70
+ end
71
+
72
+ ##============================================================##
73
+ ## Restart sidekiq
74
+ ##============================================================##
75
+ desc "Restart sidekiq"
76
+ task :restart do
77
+ on roles(:app) do
78
+ sudo "systemctl restart #{Capistrano::Immosquare::Helpers.service_name("sidekiq")}"
79
+ end
80
+ end
81
+ end
@@ -6,9 +6,10 @@ namespace :solid_queue do
6
6
  desc "Install SolidQueue service"
7
7
  task :install do
8
8
  on roles(:app) do
9
- template_path = File.read(Capistrano::SolidQueue::Helpers.template_path("solid_queue"))
9
+ template_path = File.read(Capistrano::Immosquare::Helpers.template_path("solid_queue"))
10
10
  result = ERB.new(template_path).result(binding)
11
- result_path = Capistrano::SolidQueue::Helpers.result_path
11
+ result_path = Capistrano::Immosquare::Helpers.result_path("solid_queue")
12
+ service_name = Capistrano::Immosquare::Helpers.service_name("solid_queue")
12
13
 
13
14
  ##============================================================##
14
15
  ## Upload the service file to the server
@@ -18,13 +19,13 @@ namespace :solid_queue do
18
19
  ##============================================================##
19
20
  ## Move the service file to the systemd directory
20
21
  ##============================================================##
21
- sudo "mv #{result_path} /etc/systemd/system/#{Capistrano::SolidQueue::Helpers.service_name}"
22
+ sudo "mv #{result_path} /etc/systemd/system/#{service_name}"
22
23
 
23
24
  ##============================================================##
24
25
  ## Reload the systemd daemon and quiet the service
25
26
  ##============================================================##
26
27
  sudo "systemctl daemon-reload"
27
- sudo "systemctl enable #{Capistrano::SolidQueue::Helpers.service_name}"
28
+ sudo "systemctl enable #{service_name}"
28
29
  end
29
30
  end
30
31
 
@@ -34,7 +35,7 @@ namespace :solid_queue do
34
35
  desc "Uninstall SolidQueue service"
35
36
  task :uninstall do
36
37
  on roles(:app) do
37
- service_name = Capistrano::SolidQueue::Helpers.service_name
38
+ service_name = Capistrano::Immosquare::Helpers.service_name("solid_queue")
38
39
 
39
40
  if test("systemctl list-units --full -all | grep -Fq '#{service_name}'")
40
41
  sudo("systemctl stop #{service_name}")
@@ -54,7 +55,7 @@ namespace :solid_queue do
54
55
  desc "Start solid_queue"
55
56
  task :start do
56
57
  on roles(:app) do
57
- sudo "systemctl start #{Capistrano::SolidQueue::Helpers.service_name}"
58
+ sudo "systemctl start #{Capistrano::Immosquare::Helpers.service_name("solid_queue")}"
58
59
  end
59
60
  end
60
61
 
@@ -64,7 +65,7 @@ namespace :solid_queue do
64
65
  desc "Stop solid_queue (force immediate termination)"
65
66
  task :stop do
66
67
  on roles(:app) do
67
- sudo "systemctl stop #{Capistrano::SolidQueue::Helpers.service_name}"
68
+ sudo "systemctl stop #{Capistrano::Immosquare::Helpers.service_name("solid_queue")}"
68
69
  end
69
70
  end
70
71
 
@@ -74,7 +75,7 @@ namespace :solid_queue do
74
75
  desc "Restart solid_queue"
75
76
  task :restart do
76
77
  on roles(:app) do
77
- sudo "systemctl restart #{Capistrano::SolidQueue::Helpers.service_name}"
78
+ sudo "systemctl restart #{Capistrano::Immosquare::Helpers.service_name("solid_queue")}"
78
79
  end
79
80
  end
80
81
  end
@@ -0,0 +1,26 @@
1
+ [Unit]
2
+ Description=Puma Server for <%= "#{fetch(:application)} (#{fetch(:stage)})" %>
3
+ After=syslog.target network.target
4
+
5
+
6
+ [Service]
7
+ Type=notify
8
+ WatchdogSec=10
9
+ User=<%= fetch(:puma_user) %>
10
+ WorkingDirectory=<%= current_path %>
11
+ ExecStart=<%= "#{Capistrano::Immosquare::Helpers.expanded_bundle_command} exec puma -e #{fetch(:stage)}" %>
12
+ ExecReload=/bin/kill -USR1 $MAINPID
13
+
14
+
15
+ RestartSec=1
16
+ Restart=on-failure
17
+
18
+
19
+ StandardOutput=append:<%= shared_path %>/log/puma_access.log
20
+ StandardError=append:<%= shared_path %>/log/puma_error.log
21
+
22
+
23
+ SyslogIdentifier=<%= fetch(:puma_service_unit_name) %>
24
+
25
+ [Install]
26
+ WantedBy=default.target
@@ -0,0 +1,26 @@
1
+ [Unit]
2
+ Description=Sidekiq for <%= "#{fetch(:application)} (#{fetch(:stage)})" %>
3
+ After=syslog.target network.target
4
+
5
+
6
+ [Service]
7
+ Type=notify
8
+ WatchdogSec=10
9
+ User=<%= fetch(:sidekiq_user) %>
10
+ WorkingDirectory=<%= current_path %>
11
+ ExecStart=<%= "#{Capistrano::Immosquare::Helpers.expanded_bundle_command} exec sidekiq -e #{fetch(:stage)}" %>
12
+
13
+ UMask=0002
14
+
15
+ RestartSec=1
16
+ Restart=on-failure
17
+
18
+
19
+ StandardOutput=append:<%= shared_path %>/log/sidekiq_access.log
20
+ StandardError=append:<%= shared_path %>/log/sidekiq_error.log
21
+
22
+
23
+ SyslogIdentifier=<%= fetch(:sidekiq_service_unit_name) %>
24
+
25
+ [Install]
26
+ WantedBy=default.target
@@ -8,13 +8,13 @@ Environment=RAILS_ENV=<%= fetch(:stage) %>
8
8
  User=<%= fetch(:solid_queue_user) %>
9
9
  WorkingDirectory=<%= current_path %>
10
10
 
11
- ExecStart=<%= Capistrano::SolidQueue::Helpers.expanded_bundle_command %> exec rake solid_queue:start
11
+ ExecStart=<%= Capistrano::Immosquare::Helpers.expanded_bundle_command %> exec rake solid_queue:start
12
12
  ExecReload=/bin/kill -HUP $MAINPID
13
13
  ExecStop=/bin/kill -TERM $MAINPID
14
14
 
15
15
 
16
- StandardOutput=append:<%= shared_path %>/log/solidqueue_access.log
17
- StandardError=append:<%= shared_path %>/log/solidqueue_error.log
16
+ StandardOutput=append:<%= shared_path %>/log/solid_queue_access.log
17
+ StandardError=append:<%= shared_path %>/log/solid_queue_error.log
18
18
 
19
19
  RestartSec=1
20
20
  Restart=on-failure
@@ -22,4 +22,4 @@ Restart=on-failure
22
22
  SyslogIdentifier=<%= fetch(:solid_queue_service_unit_name) %>
23
23
 
24
24
  [Install]
25
- WantedBy=multi-user.target
25
+ WantedBy=default.target
@@ -1,3 +1,3 @@
1
1
  module ImmosquareCapistrano
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.1.2".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immosquare-capistrano
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - IMMO SQUARE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-17 00:00:00.000000000 Z
11
+ date: 2024-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -35,8 +35,14 @@ files:
35
35
  - lib/immosquare-capistrano/version.rb
36
36
  - lib/immosquare/capistrano/defaults.rb
37
37
  - lib/immosquare/capistrano/helpers.rb
38
+ - lib/immosquare/capistrano/puma.rb
39
+ - lib/immosquare/capistrano/sidekiq.rb
38
40
  - lib/immosquare/capistrano/solid_queue.rb
41
+ - lib/immosquare/capistrano/tasks/puma.rake
42
+ - lib/immosquare/capistrano/tasks/sidekiq.rake
39
43
  - lib/immosquare/capistrano/tasks/solid_queue.rake
44
+ - lib/immosquare/capistrano/templates/puma.service.erb
45
+ - lib/immosquare/capistrano/templates/sidekiq.service.erb
40
46
  - lib/immosquare/capistrano/templates/solid_queue.service.erb
41
47
  homepage: https://github.com/IMMOSQUARE/immosquare-capistrano
42
48
  licenses: