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 +4 -4
- data/README.md +8 -8
- data/lib/capistrano/systemd/multiservice/system_service.rb +124 -0
- data/lib/capistrano/systemd/multiservice/version.rb +2 -10
- data/lib/capistrano/systemd/multiservice.rb +4 -104
- data/lib/capistrano/tasks/systemd/{multiservice.rake → multiservice/system_service.rake} +0 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2047d118d3aa56c85a22f1a77c68d26e735e5d9c082393b2a460a6718047f26d
|
4
|
+
data.tar.gz: 3652b1dd931ad5207dd404934224671a6cadfa2b231f9c7865652fb3b709af45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
30
|
-
install_plugin Capistrano::Systemd::MultiService.
|
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.
|
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.
|
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.
|
116
|
-
install_plugin Capistrano::Systemd::MultiService.
|
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
|
-
|
12
|
-
VERSION = "0.1.0.
|
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
|
-
|
9
|
-
|
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
|
File without changes
|
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.
|
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-
|
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
|