capistrano-systemd-multiservice 0.1.0.beta5 → 0.1.0.beta6

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: 34e907c342bb48b769dcda1949f5f32e9b4c22fc2706429515c8a3c0fa364247
4
- data.tar.gz: 8fe738be3e7bf63ac8da2f6b232e54b944a9c3d5a166ed8588306c1ab9bc4eb9
3
+ metadata.gz: 2047d118d3aa56c85a22f1a77c68d26e735e5d9c082393b2a460a6718047f26d
4
+ data.tar.gz: 3652b1dd931ad5207dd404934224671a6cadfa2b231f9c7865652fb3b709af45
5
5
  SHA512:
6
- metadata.gz: eafb7fd4f40ea4cdae224cc9ec8325097b2361587f699cb5595f0e3d33bebfb487f7a3d1f90f7eff7c1547e39a147916e7b37032c5943c04278e33dcac8dd326
7
- data.tar.gz: 6ad4883b9e6ea4b3004e1cf92f2d63ca9a09ad96da94abb9b8d16d513e99af9f51ed998932f8fcc3ec4c421bd1b7fc54d07c7d9adec9b6fd4015a24a51d6033e
6
+ metadata.gz: ec6a1ea1067b9b55667a105b03631e32f6e227729dad674822fb45d9c828db4c133d4cb9c52de7f7f1e498b007a37081b189d862c6b6f53bcc08f597dc389592
7
+ data.tar.gz: ff2e0e40974270950668461097a0a00bf022079c2fc940f20c7fe7263b6f238a2d00072bc6ca0b0d83dbc4127303cddd3fa9c63ca27a5013478c3441cfcb4e4c
data/README.md CHANGED
@@ -26,8 +26,8 @@ Add these lines to your Capfile:
26
26
 
27
27
  ```ruby
28
28
  require "capistrano/systemd/multiservice"
29
- install_plugin Capistrano::Systemd::MultiService.new("example1")
30
- install_plugin Capistrano::Systemd::MultiService.new("example2")
29
+ install_plugin Capistrano::Systemd::MultiService.new_service("example1")
30
+ install_plugin Capistrano::Systemd::MultiService.new_service("example2")
31
31
  ```
32
32
 
33
33
  And put `config/systemd/example1.service.erb` (and `config/systemd/example2.service.erb`, ...) like this:
@@ -70,7 +70,7 @@ cap STAGE deploy
70
70
 
71
71
  ## Capistrano Tasks
72
72
 
73
- With `install_plugin Capistrano::Systemd::MultiService.new("example1")`,
73
+ With `install_plugin Capistrano::Systemd::MultiService.new_service("example1")`,
74
74
  following tasks are defined.
75
75
 
76
76
  - `systemd:example1:setup`
@@ -85,11 +85,11 @@ following tasks are defined.
85
85
  - `systemd:example1:enable`
86
86
  - `systemd:example1:disable`
87
87
 
88
- See lib/capistrano/tasks/systemd/multiservice.rake, lib/capistrano/systemd/multiservice.rb for details.
88
+ See lib/capistrano/tasks/systemd/multiservice/system\_service.rake, lib/capistrano/systemd/multiservice/system\_service.rb for details.
89
89
 
90
90
  ## Configuration Variables
91
91
 
92
- With `install_plugin Capistrano::Systemd::MultiService.new("example1")`,
92
+ With `install_plugin Capistrano::Systemd::MultiService.new_service("example1")`,
93
93
  following Configuration variables are defined.
94
94
 
95
95
  - `:systemd_example1_role`
@@ -100,7 +100,7 @@ following Configuration variables are defined.
100
100
  - `:systemd_example1_service`
101
101
  - `:systemd_example1_instance_services`
102
102
 
103
- See lib/capistrano/systemd/multiservice.rb for details.
103
+ See lib/capistrano/systemd/multiservice/system\_service.rb for details.
104
104
 
105
105
  ## Examples
106
106
 
@@ -112,8 +112,8 @@ See lib/capistrano/systemd/multiservice.rb for details.
112
112
  ## ...snip...
113
113
 
114
114
  require 'capistrano/systemd/multiservice'
115
- install_plugin Capistrano::Systemd::MultiService.new('unicorn')
116
- install_plugin Capistrano::Systemd::MultiService.new('delayed_job')
115
+ install_plugin Capistrano::Systemd::MultiService.new_service('unicorn')
116
+ install_plugin Capistrano::Systemd::MultiService.new_service('delayed_job')
117
117
 
118
118
  ## ...snip...
119
119
  ```
@@ -0,0 +1,124 @@
1
+ require "erb"
2
+ require "stringio"
3
+ require "capistrano/plugin"
4
+
5
+ module Capistrano
6
+ module Systemd
7
+ module MultiService
8
+ class SystemService < ::Capistrano::Plugin
9
+ attr_reader :app
10
+
11
+ def initialize(app)
12
+ @app = app
13
+ super()
14
+ end
15
+
16
+ def nsp
17
+ @app.to_sym
18
+ end
19
+
20
+ def prefix
21
+ "systemd_#{@app}"
22
+ end
23
+
24
+ def define_tasks
25
+ eval_rakefile File.expand_path("../../../tasks/systemd/multiservice/system_service.rake", __FILE__)
26
+ end
27
+
28
+ def register_hooks
29
+ after "deploy:check", "systemd:#{nsp}:validate"
30
+ after "systemd:#{nsp}:setup", "systemd:#{nsp}:daemon-reload"
31
+ after "systemd:#{nsp}:setup", "systemd:#{nsp}:enable"
32
+ before "systemd:#{nsp}:remove", "systemd:#{nsp}:disable"
33
+ after "systemd:#{nsp}:remove", "systemd:#{nsp}:daemon-reload"
34
+ end
35
+
36
+ def set_defaults
37
+ set_if_empty :"#{prefix}_role", ->{ :app }
38
+
39
+ set_if_empty :"#{prefix}_units_src", ->{ Dir["config/systemd/#{@app}{,@}.*.erb"].sort }
40
+
41
+ set_if_empty :"#{prefix}_units_dir", ->{ default_units_dir }
42
+
43
+ set_if_empty :"#{prefix}_units_dest", ->{
44
+ fetch(:"#{prefix}_units_src").map{|src|
45
+ "%s/%s_%s" % [ fetch(:"#{prefix}_units_dir"), fetch(:application), File.basename(src, ".erb") ]
46
+ }
47
+ }
48
+
49
+ set_if_empty :"#{prefix}_instances", ->{
50
+ if fetch(:"#{prefix}_units_dest").map{|dst| File.basename(dst) }.find{|f| f =~ /@\.service\z/ }
51
+ 1.times.to_a
52
+ else
53
+ nil
54
+ end
55
+ }
56
+
57
+ set_if_empty :"#{prefix}_service", ->{
58
+ service = fetch(:"#{prefix}_units_dest").map{|dst| File.basename(dst) }.find{|f| f =~ /\.service\z/ && f !~ /@\.service\z/ }
59
+ service || fetch(:"#{prefix}_instance_services")
60
+ }
61
+
62
+ set_if_empty :"#{prefix}_instance_services", ->{
63
+ if fetch(:"#{prefix}_instances")
64
+ fetch(:"#{prefix}_instances").map{|i|
65
+ service_template = fetch(:"#{prefix}_units_dest").map{|dst| File.basename(dst) }.find{|f| f =~ /@\.service\z/ }
66
+ service_template && service_template.sub(/@\.service\z/, "@#{i}.service")
67
+ }
68
+ else
69
+ []
70
+ end
71
+ }
72
+ end
73
+
74
+ def setup
75
+ fetch(:"#{prefix}_units_src").zip(fetch(:"#{prefix}_units_dest")).each do |src, dest|
76
+ buf = StringIO.new(ERB.new(File.read(src), nil, 2).result(binding))
77
+ setup_service buf, src, dest
78
+ end
79
+ end
80
+
81
+ def remove
82
+ backend.sudo :rm, '-f', '--', fetch(:"#{prefix}_units_dest")
83
+ end
84
+
85
+ def validate
86
+ fetch(:"#{prefix}_units_dest").each do |dest|
87
+ unless backend.test("[ -f #{dest} ]")
88
+ backend.error "#{dest} not found"
89
+ exit 1
90
+ end
91
+ end
92
+ end
93
+
94
+ def daemon_reload
95
+ systemctl :"daemon-reload"
96
+ end
97
+
98
+ %i[start stop reload restart reload-or-restart enable disable].each do |act|
99
+ define_method act.to_s.tr('-','_') do
100
+ systemctl act, fetch(:"#{prefix}_service")
101
+ end
102
+ end
103
+
104
+ def systemctl(*args)
105
+ args.unshift :sudo, :systemctl
106
+ backend.execute(*args)
107
+ end
108
+
109
+ def default_units_dir
110
+ "/etc/systemd/system"
111
+ end
112
+
113
+ private
114
+
115
+ def setup_service(buf, src, dest)
116
+ remote_tmp = "#{fetch(:tmp_dir)}/#{File.basename(src, ".erb")}"
117
+ backend.upload! buf, remote_tmp
118
+ backend.sudo :install, '-m 644 -o root -g root -D', remote_tmp, dest
119
+ backend.execute :rm, remote_tmp
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -1,15 +1,7 @@
1
- begin
2
- require "capistrano/plugin"
3
- rescue LoadError
4
- module Capistrano
5
- class Plugin; end
6
- end
7
- end
8
-
9
1
  module Capistrano
10
2
  module Systemd
11
- class MultiService < ::Capistrano::Plugin
12
- VERSION = "0.1.0.beta5"
3
+ module MultiService
4
+ VERSION = "0.1.0.beta6"
13
5
  end
14
6
  end
15
7
  end
@@ -1,111 +1,11 @@
1
- require "erb"
2
- require "stringio"
3
- require "capistrano/plugin"
4
1
  require "capistrano/systemd/multiservice/version"
2
+ require "capistrano/systemd/multiservice/system_service"
5
3
 
6
4
  module Capistrano
7
5
  module Systemd
8
- class MultiService < ::Capistrano::Plugin
9
- attr_reader :app
10
-
11
- def initialize(app)
12
- @app = app
13
- super()
14
- end
15
-
16
- def nsp
17
- @app.to_sym
18
- end
19
-
20
- def prefix
21
- "systemd_#{@app}"
22
- end
23
-
24
- def define_tasks
25
- eval_rakefile File.expand_path("../../tasks/systemd/multiservice.rake", __FILE__)
26
- end
27
-
28
- def register_hooks
29
- after "deploy:check", "systemd:#{nsp}:validate"
30
- after "systemd:#{nsp}:setup", "systemd:#{nsp}:daemon-reload"
31
- after "systemd:#{nsp}:setup", "systemd:#{nsp}:enable"
32
- before "systemd:#{nsp}:remove", "systemd:#{nsp}:disable"
33
- after "systemd:#{nsp}:remove", "systemd:#{nsp}:daemon-reload"
34
- end
35
-
36
- def set_defaults
37
- set_if_empty :"#{prefix}_role", ->{ :app }
38
-
39
- set_if_empty :"#{prefix}_units_src", ->{ Dir["config/systemd/#{@app}{,@}.*.erb"].sort }
40
-
41
- set_if_empty :"#{prefix}_units_dir", ->{ "/etc/systemd/system" }
42
-
43
- set_if_empty :"#{prefix}_units_dest", ->{
44
- fetch(:"#{prefix}_units_src").map{|src|
45
- "%s/%s_%s" % [ fetch(:"#{prefix}_units_dir"), fetch(:application), File.basename(src, ".erb") ]
46
- }
47
- }
48
-
49
- set_if_empty :"#{prefix}_instances", ->{
50
- if fetch(:"#{prefix}_units_dest").map{|dst| File.basename(dst) }.find{|f| f =~ /@\.service\z/ }
51
- 1.times.to_a
52
- else
53
- nil
54
- end
55
- }
56
-
57
- set_if_empty :"#{prefix}_service", ->{
58
- service = fetch(:"#{prefix}_units_dest").map{|dst| File.basename(dst) }.find{|f| f =~ /\.service\z/ && f !~ /@\.service\z/ }
59
- service || fetch(:"#{prefix}_instance_services")
60
- }
61
-
62
- set_if_empty :"#{prefix}_instance_services", ->{
63
- if fetch(:"#{prefix}_instances")
64
- fetch(:"#{prefix}_instances").map{|i|
65
- service_template = fetch(:"#{prefix}_units_dest").map{|dst| File.basename(dst) }.find{|f| f =~ /@\.service\z/ }
66
- service_template && service_template.sub(/@\.service\z/, "@#{i}.service")
67
- }
68
- else
69
- []
70
- end
71
- }
72
- end
73
-
74
- def setup
75
- fetch(:"#{prefix}_units_src").zip(fetch(:"#{prefix}_units_dest")).each do |src, dest|
76
- remote_tmp = "#{fetch(:tmp_dir)}/#{File.basename(src, ".erb")}"
77
- backend.upload! StringIO.new(ERB.new(File.read(src), nil, 2).result(binding)), remote_tmp
78
- backend.sudo :install, '-m 644 -o root -g root -D', remote_tmp, dest
79
- backend.execute :rm, remote_tmp
80
- end
81
- end
82
-
83
- def remove
84
- backend.sudo :rm, '-f', '--', fetch(:"#{prefix}_units_dest")
85
- end
86
-
87
- def validate
88
- fetch(:"#{prefix}_units_dest").each do |dest|
89
- unless backend.test("[ -f #{dest} ]")
90
- backend.error "#{dest} not found"
91
- exit 1
92
- end
93
- end
94
- end
95
-
96
- def daemon_reload
97
- systemctl :"daemon-reload"
98
- end
99
-
100
- %i[start stop reload restart reload-or-restart enable disable].each do |act|
101
- define_method act.to_s.tr('-','_') do
102
- systemctl act, fetch(:"#{prefix}_service")
103
- end
104
- end
105
-
106
- def systemctl(*args)
107
- args.unshift :sudo, :systemctl
108
- backend.execute(*args)
6
+ module MultiService
7
+ def self.new_service(app)
8
+ SystemService.new(app)
109
9
  end
110
10
  end
111
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-systemd-multiservice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta5
4
+ version: 0.1.0.beta6
5
5
  platform: ruby
6
6
  authors:
7
7
  - YAMADA Tsuyoshi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-06 00:00:00.000000000 Z
11
+ date: 2018-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -104,8 +104,9 @@ files:
104
104
  - bin/setup
105
105
  - capistrano-systemd-multiservice.gemspec
106
106
  - lib/capistrano/systemd/multiservice.rb
107
+ - lib/capistrano/systemd/multiservice/system_service.rb
107
108
  - lib/capistrano/systemd/multiservice/version.rb
108
- - lib/capistrano/tasks/systemd/multiservice.rake
109
+ - lib/capistrano/tasks/systemd/multiservice/system_service.rake
109
110
  homepage: https://github.com/groovenauts/capistrano-systemd-multiservice
110
111
  licenses:
111
112
  - MIT