serverkit 0.5.1 → 0.6.0
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 +4 -4
- data/CHANGELOG.md +3 -0
- data/doc/resource.md +3 -1
- data/lib/serverkit/backends/base_backend.rb +5 -23
- data/lib/serverkit/resources/base.rb +31 -5
- data/lib/serverkit/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d638957343d75f83244b7d7589662ee2364c7bd6
|
4
|
+
data.tar.gz: a16ef58fad113e7e9e58305a8ec4146d604bf7ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 498492872c31a830b67dc9cbcd2fbef34b8149aa2391428540168a93e0268fbcfa37f2655b93d14fff502cf4144f128357f2be26b6e1349677f7dc317f8cfb14
|
7
|
+
data.tar.gz: c671b47059e43d9560d5ecc50580e0b9a0a3e7aa24b81c3f1951ea084fdbbbe85e92990682d8802e338f09129b1aab65a3082634383d23cae51762d29973bc75
|
data/CHANGELOG.md
CHANGED
data/doc/resource.md
CHANGED
@@ -7,9 +7,11 @@ By default, all types of resource can or must have the following attributes:
|
|
7
7
|
|
8
8
|
- type - what type this resource represents (required)
|
9
9
|
- check_script - pass shell script to override the `#check` phase
|
10
|
-
-
|
10
|
+
- cwd - pass current working directory path
|
11
11
|
- id - change resource identifier used in log, and also used for `notify`
|
12
12
|
- notify - specify an Array of handler ids that should be applied after changed
|
13
|
+
- recheck_script - pass shell script to override the `#recheck` phase (runned after `#apply`)
|
14
|
+
- user - specify user for `sudo -u`
|
13
15
|
|
14
16
|
## Example
|
15
17
|
Here is a tiny example recipe that has only one resource with `type` and `name` attributes.
|
@@ -5,6 +5,7 @@ module Serverkit
|
|
5
5
|
module Backends
|
6
6
|
class BaseBackend
|
7
7
|
delegate(
|
8
|
+
:command,
|
8
9
|
:send_file,
|
9
10
|
to: :specinfra_backend,
|
10
11
|
)
|
@@ -13,21 +14,6 @@ module Serverkit
|
|
13
14
|
@log_level = log_level
|
14
15
|
end
|
15
16
|
|
16
|
-
# @return [true, false]
|
17
|
-
def check_command(*args)
|
18
|
-
run_command(*args).success?
|
19
|
-
end
|
20
|
-
|
21
|
-
# @return [true, false]
|
22
|
-
def check_command_from_identifier(*args)
|
23
|
-
run_command_from_identifier(*args).success?
|
24
|
-
end
|
25
|
-
|
26
|
-
# @return [String]
|
27
|
-
def get_command_from_identifier(*args)
|
28
|
-
specinfra_backend.command.get(*args)
|
29
|
-
end
|
30
|
-
|
31
17
|
# @note Override me
|
32
18
|
# @return [String]
|
33
19
|
# @example "localhost"
|
@@ -42,21 +28,17 @@ module Serverkit
|
|
42
28
|
end
|
43
29
|
end
|
44
30
|
|
31
|
+
# @param [String] command one-line shell script to be executed on remote machine
|
45
32
|
# @return [Specinfra::CommandResult]
|
46
|
-
def run_command(
|
47
|
-
logger.debug("Running #{
|
48
|
-
specinfra_backend.run_command(
|
33
|
+
def run_command(command)
|
34
|
+
logger.debug("Running #{command} on #{host}")
|
35
|
+
specinfra_backend.run_command(command).tap do |result|
|
49
36
|
logger.debug(result.stdout) unless result.stdout.empty?
|
50
37
|
logger.debug(result.stderr) unless result.stderr.empty?
|
51
38
|
logger.debug("Finished with #{result.exit_status} on #{host}")
|
52
39
|
end
|
53
40
|
end
|
54
41
|
|
55
|
-
# @return [Specinfra::CommandResult]
|
56
|
-
def run_command_from_identifier(*args)
|
57
|
-
run_command(get_command_from_identifier(*args))
|
58
|
-
end
|
59
|
-
|
60
42
|
def send_file(from, to)
|
61
43
|
logger.debug("Sending file #{from} to #{to}")
|
62
44
|
specinfra_backend.send_file(from, to)
|
@@ -34,17 +34,14 @@ module Serverkit
|
|
34
34
|
attr_reader :attributes, :check_result, :recheck_result, :recipe
|
35
35
|
|
36
36
|
attribute :check_script, type: String
|
37
|
+
attribute :cwd, type: String
|
37
38
|
attribute :id, type: String
|
38
39
|
attribute :notify, type: Array
|
39
40
|
attribute :recheck_script, type: String
|
40
41
|
attribute :type, type: String
|
42
|
+
attribute :user, type: String
|
41
43
|
|
42
44
|
delegate(
|
43
|
-
:check_command,
|
44
|
-
:check_command_from_identifier,
|
45
|
-
:get_command_from_identifier,
|
46
|
-
:run_command,
|
47
|
-
:run_command_from_identifier,
|
48
45
|
:send_file,
|
49
46
|
to: :backend,
|
50
47
|
)
|
@@ -64,6 +61,21 @@ module Serverkit
|
|
64
61
|
attribute_validation_errors
|
65
62
|
end
|
66
63
|
|
64
|
+
# @return [true, false]
|
65
|
+
def check_command(*args)
|
66
|
+
run_command(*args).success?
|
67
|
+
end
|
68
|
+
|
69
|
+
# @return [true, false]
|
70
|
+
def check_command_from_identifier(*args)
|
71
|
+
run_command_from_identifier(*args).success?
|
72
|
+
end
|
73
|
+
|
74
|
+
# @return [String]
|
75
|
+
def get_command_from_identifier(*args)
|
76
|
+
backend.command.get(*args)
|
77
|
+
end
|
78
|
+
|
67
79
|
# @return [Array<Serverkit::Resource>]
|
68
80
|
def handlers
|
69
81
|
@handlers ||= Array(notify).map do |id|
|
@@ -209,6 +221,20 @@ module Serverkit
|
|
209
221
|
end
|
210
222
|
end
|
211
223
|
|
224
|
+
# @note Wraps backend.run_command for `cwd` and `user` attributes
|
225
|
+
# @param [String] command one-line shell script to be executed on remote machine
|
226
|
+
# @return [Specinfra::CommandResult]
|
227
|
+
def run_command(command)
|
228
|
+
command = "cd #{Shellwords.escape(cwd)} && #{command}" unless cwd.nil?
|
229
|
+
command = "sudo -u #{user} -- /bin/sh -c #{Shellwords.escape(command)}" unless user.nil?
|
230
|
+
backend.run_command(command)
|
231
|
+
end
|
232
|
+
|
233
|
+
# @return [Specinfra::CommandResult]
|
234
|
+
def run_command_from_identifier(*args)
|
235
|
+
run_command(get_command_from_identifier(*args))
|
236
|
+
end
|
237
|
+
|
212
238
|
# Update remote file content on given path with given content
|
213
239
|
# @param [String] content
|
214
240
|
# @param [String] path
|
data/lib/serverkit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serverkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|