omnibus-ctl 0.5.0 → 0.6.10
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 +5 -5
- data/LICENSE +201 -0
- data/bin/omnibus-ctl +3 -3
- data/lib/omnibus-ctl/version.rb +1 -1
- data/lib/omnibus-ctl.rb +153 -121
- metadata +36 -8
- data/README.md +0 -100
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d5a9e7ad1cc7b71b4a63de91b45c0defc0e980a6ec79848339041eecf414493f
|
4
|
+
data.tar.gz: b0f98055e5f34965c6d61719f15c0c6231d43345b87b3ed3e65ede350103728f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44b9168f26f927b61a68d8a8d9145c6a18d4b6dad0a48e69515544c107dceb6061b2483580ac9582be750b8fd0d893bc5d77d58bd698c35de220240a28db1913
|
7
|
+
data.tar.gz: a2035e53d04247a5b8a6cfa5e777d974ec4747960de47e473c92a438e044c91a86c5d000be4db50d4bce2ba8a0f1726633e8740b9e8138c066ab254bde6a0198
|
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/bin/omnibus-ctl
CHANGED
@@ -7,9 +7,9 @@
|
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
# you may not use this file except in compliance with the License.
|
9
9
|
# You may obtain a copy of the License at
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# Unless required by applicable law or agreed to in writing, software
|
14
14
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
15
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -17,7 +17,7 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require "omnibus-ctl"
|
21
21
|
|
22
22
|
# service name: ARGV[0]
|
23
23
|
# additional modules: ARGV[1]
|
data/lib/omnibus-ctl/version.rb
CHANGED
data/lib/omnibus-ctl.rb
CHANGED
@@ -15,21 +15,22 @@
|
|
15
15
|
#
|
16
16
|
|
17
17
|
require "omnibus-ctl/version"
|
18
|
-
require
|
19
|
-
require
|
18
|
+
require "chef-utils/dist" unless defined?(ChefUtils)
|
19
|
+
require "json" unless defined?(JSON)
|
20
|
+
require "fileutils" unless defined?(FileUtils)
|
20
21
|
|
21
22
|
# For license checks
|
22
|
-
require
|
23
|
-
require
|
23
|
+
require "io/console"
|
24
|
+
require "io/wait"
|
24
25
|
|
25
26
|
module Omnibus
|
26
27
|
class Ctl
|
27
28
|
|
28
|
-
File
|
29
|
+
File.umask(022)
|
29
30
|
|
30
|
-
SV_COMMAND_NAMES = %w
|
31
|
+
SV_COMMAND_NAMES = %w{status up down once pause cont hup alarm int quit
|
31
32
|
term kill start stop restart shutdown force-stop
|
32
|
-
force-reload force-restart force-shutdown check usr1 usr2
|
33
|
+
force-reload force-restart force-shutdown check usr1 usr2}.freeze
|
33
34
|
|
34
35
|
attr_accessor :name, :display_name, :log_exclude, :base_path, :sv_path,
|
35
36
|
:service_path, :etc_path, :data_path, :log_path, :command_map, :category_command_map,
|
@@ -37,8 +38,7 @@ module Omnibus
|
|
37
38
|
|
38
39
|
attr_reader :backup_dir, :exe_name
|
39
40
|
|
40
|
-
|
41
|
-
def initialize(name, merge_service_commands=true, disp_name = nil)
|
41
|
+
def initialize(name, merge_service_commands = true, disp_name = nil)
|
42
42
|
@name = name
|
43
43
|
@service_commands = merge_service_commands
|
44
44
|
@display_name = disp_name || name
|
@@ -48,109 +48,116 @@ module Omnibus
|
|
48
48
|
@log_path = "/var/log/#{name}"
|
49
49
|
@data_path = "/var/opt/#{name}"
|
50
50
|
@etc_path = "/etc/#{name}"
|
51
|
-
@log_exclude =
|
52
|
-
@log_path_exclude = [
|
51
|
+
@log_exclude = "(config|lock|@|bz2|gz|gzip|tbz2|tgz|txz|xz|zip)"
|
52
|
+
@log_path_exclude = ["*/sasl/*"]
|
53
53
|
@fh_output = STDOUT
|
54
54
|
@kill_users = []
|
55
55
|
@verbose = false
|
56
56
|
@quiet = false
|
57
57
|
@exe_name = File.basename($0)
|
58
58
|
@force_exit = false
|
59
|
+
@global_pre_hooks = {}
|
60
|
+
|
61
|
+
# TODO(ssd) 2017-03-28: Set SVDIR explicitly. Once we fix a bug
|
62
|
+
# in our debian support, where we rely on system-installed
|
63
|
+
# runit, we can likely change this back to ENV.delete("SVDIR")
|
64
|
+
ENV["SVDIR"] = service_path
|
59
65
|
|
60
66
|
# backwards compat command map that does not have categories
|
61
|
-
@command_map = {
|
67
|
+
@command_map = {}
|
62
68
|
|
63
69
|
# categoired commands that we want by default
|
64
70
|
@category_command_map = {
|
65
71
|
"general" => {
|
66
72
|
"show-config" => {
|
67
|
-
:
|
68
|
-
:
|
73
|
+
desc: "Show the configuration that would be generated by reconfigure.",
|
74
|
+
arity: 1,
|
69
75
|
},
|
70
76
|
"reconfigure" => {
|
71
|
-
:
|
72
|
-
:
|
77
|
+
desc: "Reconfigure the application.",
|
78
|
+
arity: 2,
|
73
79
|
},
|
74
80
|
"cleanse" => {
|
75
|
-
:
|
76
|
-
:
|
81
|
+
desc: "Delete *all* #{display_name} data, and start from scratch.",
|
82
|
+
arity: 2,
|
77
83
|
},
|
78
84
|
"uninstall" => {
|
79
|
-
:
|
80
|
-
:
|
85
|
+
arity: 1,
|
86
|
+
desc: "Kill all processes and uninstall the process supervisor (data will be preserved).",
|
81
87
|
},
|
82
88
|
"help" => {
|
83
|
-
:
|
84
|
-
:
|
85
|
-
}
|
86
|
-
}
|
89
|
+
arity: 1,
|
90
|
+
desc: "Print this help message.",
|
91
|
+
},
|
92
|
+
},
|
87
93
|
}
|
88
94
|
service_command_map = {
|
89
95
|
"service-management" => {
|
90
96
|
"service-list" => {
|
91
|
-
:
|
92
|
-
:
|
97
|
+
arity: 1,
|
98
|
+
desc: "List all the services (enabled services appear with a *.)",
|
93
99
|
},
|
94
100
|
"status" => {
|
95
|
-
:
|
96
|
-
:
|
101
|
+
desc: "Show the status of all the services.",
|
102
|
+
arity: 2,
|
97
103
|
},
|
98
104
|
"tail" => {
|
99
|
-
:
|
100
|
-
:
|
105
|
+
desc: "Watch the service logs of all enabled services.",
|
106
|
+
arity: 2,
|
101
107
|
},
|
102
108
|
"start" => {
|
103
|
-
:
|
104
|
-
:
|
109
|
+
desc: "Start services if they are down, and restart them if they stop.",
|
110
|
+
arity: 2,
|
105
111
|
},
|
106
112
|
"stop" => {
|
107
|
-
:
|
108
|
-
:
|
113
|
+
desc: "Stop the services, and do not restart them.",
|
114
|
+
arity: 2,
|
109
115
|
},
|
110
116
|
"restart" => {
|
111
|
-
:
|
112
|
-
:
|
117
|
+
desc: "Stop the services if they are running, then start them again.",
|
118
|
+
arity: 2,
|
113
119
|
},
|
114
120
|
"once" => {
|
115
|
-
:
|
116
|
-
:
|
121
|
+
desc: "Start the services if they are down. Do not restart them if they stop.",
|
122
|
+
arity: 2,
|
117
123
|
},
|
118
124
|
"hup" => {
|
119
|
-
:
|
120
|
-
:
|
125
|
+
desc: "Send the services a HUP.",
|
126
|
+
arity: 2,
|
121
127
|
},
|
122
128
|
"term" => {
|
123
|
-
:
|
124
|
-
:
|
129
|
+
desc: "Send the services a TERM.",
|
130
|
+
arity: 2,
|
125
131
|
},
|
126
132
|
"int" => {
|
127
|
-
:
|
128
|
-
:
|
133
|
+
desc: "Send the services an INT.",
|
134
|
+
arity: 2,
|
129
135
|
},
|
130
136
|
"kill" => {
|
131
|
-
:
|
132
|
-
:
|
137
|
+
desc: "Send the services a KILL.",
|
138
|
+
arity: 2,
|
133
139
|
},
|
134
140
|
"graceful-kill" => {
|
135
|
-
:
|
136
|
-
:
|
141
|
+
desc: "Attempt a graceful stop, then SIGKILL the entire process group.",
|
142
|
+
arity: 2,
|
137
143
|
},
|
138
144
|
"usr1" => {
|
139
|
-
:
|
140
|
-
:
|
145
|
+
desc: "Send the services a USR1.",
|
146
|
+
arity: 2,
|
141
147
|
},
|
142
148
|
"usr2" => {
|
143
|
-
:
|
144
|
-
:
|
145
|
-
}
|
146
|
-
}
|
149
|
+
desc: "Send the services a USR2.",
|
150
|
+
arity: 2,
|
151
|
+
},
|
152
|
+
},
|
147
153
|
}
|
148
154
|
@category_command_map.merge!(service_command_map) if service_commands?
|
149
155
|
end
|
150
156
|
|
151
157
|
def self.to_method_name(name)
|
152
|
-
name.gsub(/-/,
|
158
|
+
name.gsub(/-/, "_").to_sym
|
153
159
|
end
|
160
|
+
|
154
161
|
def to_method_name(name)
|
155
162
|
Ctl.to_method_name(name)
|
156
163
|
end
|
@@ -182,24 +189,25 @@ module Omnibus
|
|
182
189
|
end
|
183
190
|
|
184
191
|
def load_file(filepath)
|
185
|
-
eval(IO.read(filepath), nil, filepath, 1)
|
192
|
+
eval(IO.read(filepath), nil, filepath, 1) # rubocop: disable Security/Eval
|
186
193
|
end
|
187
194
|
|
188
|
-
def add_command(name, description, arity=1, &block)
|
189
|
-
@command_map[name] = { :
|
190
|
-
|
191
|
-
# Ruby does not like dashes in method names
|
192
|
-
method_name = to_method_name(name).to_sym
|
193
|
-
metaclass.send(:define_method, method_name) { |*args| block.call(*args) }
|
195
|
+
def add_command(name, description, arity = 1, &block)
|
196
|
+
@command_map[name] = { desc: description, arity: arity }
|
197
|
+
self.class.send(:define_method, to_method_name(name).to_sym) { |*args| block.call(*args) }
|
194
198
|
end
|
195
199
|
|
196
|
-
def add_command_under_category(name, category, description, arity=1, &block)
|
200
|
+
def add_command_under_category(name, category, description, arity = 1, &block)
|
197
201
|
# add new category if it doesn't exist
|
198
|
-
@category_command_map[category]
|
199
|
-
@category_command_map[category][name] = { :
|
200
|
-
|
201
|
-
|
202
|
-
|
202
|
+
@category_command_map[category] ||= {}
|
203
|
+
@category_command_map[category][name] = { desc: description, arity: arity }
|
204
|
+
self.class.send(:define_method, to_method_name(name).to_sym) { |*args| block.call(*args) }
|
205
|
+
end
|
206
|
+
|
207
|
+
def add_global_pre_hook(name, &block)
|
208
|
+
method_name = to_method_name("#{name}_global_pre_hook").to_sym
|
209
|
+
@global_pre_hooks[name] = method_name
|
210
|
+
self.class.send(:define_method, method_name, block)
|
203
211
|
end
|
204
212
|
|
205
213
|
def exit!(code)
|
@@ -212,17 +220,17 @@ module Omnibus
|
|
212
220
|
end
|
213
221
|
|
214
222
|
def get_pgrp_from_pid(pid)
|
215
|
-
ps
|
223
|
+
ps = `which ps`.chomp
|
216
224
|
`#{ps} -p #{pid} -o pgrp=`.chomp
|
217
225
|
end
|
218
226
|
|
219
227
|
def get_pids_from_pgrp(pgrp)
|
220
|
-
pgrep
|
228
|
+
pgrep = `which pgrep`.chomp
|
221
229
|
`#{pgrep} -g #{pgrp}`.split(/\n/).join(" ")
|
222
230
|
end
|
223
231
|
|
224
232
|
def sigkill_pgrp(pgrp)
|
225
|
-
pkill
|
233
|
+
pkill = `which pkill`.chomp
|
226
234
|
run_command("#{pkill} -9 -g #{pgrp}")
|
227
235
|
end
|
228
236
|
|
@@ -243,26 +251,26 @@ module Omnibus
|
|
243
251
|
def cleanup_procs_and_nuke(filestr, calling_method = nil)
|
244
252
|
run_sv_command("stop")
|
245
253
|
|
246
|
-
FileUtils.rm_f("/etc/init/#{name}-runsvdir.conf") if File.
|
247
|
-
run_command("egrep -v '#{base_path}/embedded/bin/runsvdir-start' /etc/inittab > /etc/inittab.new && mv /etc/inittab.new /etc/inittab") if File.
|
254
|
+
FileUtils.rm_f("/etc/init/#{name}-runsvdir.conf") if File.exist?("/etc/init/#{name}-runsvdir.conf")
|
255
|
+
run_command("egrep -v '#{base_path}/embedded/bin/runsvdir-start' /etc/inittab > /etc/inittab.new && mv /etc/inittab.new /etc/inittab") if File.exist?("/etc/inittab")
|
248
256
|
run_command("kill -1 1")
|
249
257
|
|
250
258
|
@backup_dir = Time.now.strftime("/root/#{name}-cleanse-%FT%R")
|
251
259
|
|
252
|
-
FileUtils.mkdir_p("/root") unless File.
|
260
|
+
FileUtils.mkdir_p("/root") unless File.exist?("/root")
|
253
261
|
FileUtils.rm_rf(backup_dir)
|
254
|
-
FileUtils.cp_r(etc_path, backup_dir) if File.
|
262
|
+
FileUtils.cp_r(etc_path, backup_dir) if File.exist?(etc_path)
|
255
263
|
run_command("rm -rf #{filestr}")
|
256
264
|
graceful_kill
|
257
265
|
|
258
266
|
log "Terminating processes running under application users. This will take a few seconds."
|
259
|
-
run_command("pkill -HUP -u #{kill_users.join(
|
267
|
+
run_command("pkill -HUP -u #{kill_users.join(",")}") if kill_users.length > 0
|
260
268
|
run_command("pkill -HUP -f 'runsvdir -P #{service_path}'")
|
261
269
|
sleep 3
|
262
|
-
run_command("pkill -TERM -u #{kill_users.join(
|
270
|
+
run_command("pkill -TERM -u #{kill_users.join(",")}") if kill_users.length > 0
|
263
271
|
run_command("pkill -TERM -f 'runsvdir -P #{service_path}'")
|
264
272
|
sleep 3
|
265
|
-
run_command("pkill -KILL -u #{kill_users.join(
|
273
|
+
run_command("pkill -KILL -u #{kill_users.join(",")}") if kill_users.length > 0
|
266
274
|
run_command("pkill -KILL -f 'runsvdir -P #{service_path}'")
|
267
275
|
|
268
276
|
get_all_services.each do |die_daemon_die|
|
@@ -286,13 +294,13 @@ module Omnibus
|
|
286
294
|
This command will delete *all* local configuration, log, and
|
287
295
|
variable data associated with #{display_name}.
|
288
296
|
EOM
|
289
|
-
if
|
297
|
+
if with_external
|
290
298
|
log <<EOM
|
291
299
|
This will also delete externally hosted #{display_name} data.
|
292
300
|
This means that any service you have configured as 'external'
|
293
301
|
will have any #{display_name} permanently deleted.
|
294
302
|
EOM
|
295
|
-
elsif
|
303
|
+
elsif not external_services.empty?
|
296
304
|
log <<EOM
|
297
305
|
|
298
306
|
Important note: If you also wish to delete externally hosted #{display_name}
|
@@ -324,9 +332,8 @@ EOM
|
|
324
332
|
cleanup_procs_and_nuke("#{service_path}/* /tmp/opt #{data_path} #{etc_path} #{log_path}", "cleanse")
|
325
333
|
end
|
326
334
|
|
327
|
-
|
328
335
|
def get_all_services_files
|
329
|
-
Dir[File.join(sv_path,
|
336
|
+
Dir[File.join(sv_path, "*")]
|
330
337
|
end
|
331
338
|
|
332
339
|
def get_all_services
|
@@ -337,7 +344,7 @@ EOM
|
|
337
344
|
File.symlink?("#{service_path}/#{service_name}")
|
338
345
|
end
|
339
346
|
|
340
|
-
def run_sv_command(sv_cmd, service=nil)
|
347
|
+
def run_sv_command(sv_cmd, service = nil)
|
341
348
|
exit_status = 0
|
342
349
|
sv_cmd = "1" if sv_cmd == "usr1"
|
343
350
|
sv_cmd = "2" if sv_cmd == "usr2"
|
@@ -390,7 +397,7 @@ EOM
|
|
390
397
|
end
|
391
398
|
|
392
399
|
# All other services respond normally to p-c-c * commands
|
393
|
-
|
400
|
+
true
|
394
401
|
end
|
395
402
|
|
396
403
|
# removed services are configured via the attributes file in
|
@@ -422,7 +429,8 @@ EOM
|
|
422
429
|
# 'opscode', not 'private-chef'
|
423
430
|
def package_name
|
424
431
|
case @name
|
425
|
-
|
432
|
+
# The "opscode" in /opt/opscode
|
433
|
+
when ::ChefUtils::Dist::Org::LEGACY_CONF_DIR
|
426
434
|
"private-chef"
|
427
435
|
else
|
428
436
|
@name
|
@@ -431,24 +439,24 @@ EOM
|
|
431
439
|
|
432
440
|
# returns nil when chef-server-running.json does not exist
|
433
441
|
def running_config
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
end
|
442
|
+
fname = "#{etc_path}/#{::ChefUtils::Dist::Server::SERVER}-running.json"
|
443
|
+
@running_config ||= if File.exist?(fname)
|
444
|
+
JSON.parse(File.read(fname))
|
445
|
+
end
|
439
446
|
end
|
440
447
|
|
441
448
|
# Helper function that returns the hash of config hashes that have the key 'external' : true
|
442
449
|
# in the running config. If none exist it will return an empty hash.
|
443
450
|
def external_services
|
444
|
-
@external_services
|
451
|
+
@external_services ||= running_package_config.select { |k, v| v.class == Hash and v["external"] == true }
|
445
452
|
end
|
446
453
|
|
447
454
|
# Helper function that returns true if an external service entry exists for
|
448
455
|
# the named service
|
449
456
|
def service_external?(service)
|
450
457
|
return false if service.nil?
|
451
|
-
|
458
|
+
|
459
|
+
external_services.key? service
|
452
460
|
end
|
453
461
|
|
454
462
|
# Gives package config from the running_config.
|
@@ -456,7 +464,7 @@ EOM
|
|
456
464
|
# reference a valid key, this will return an empty hash
|
457
465
|
def running_package_config
|
458
466
|
if (cfg = running_config)
|
459
|
-
cfg[package_name.gsub(/-/,
|
467
|
+
cfg[package_name.gsub(/-/, "_")] || {}
|
460
468
|
else
|
461
469
|
{}
|
462
470
|
end
|
@@ -473,19 +481,19 @@ EOM
|
|
473
481
|
def remove_old_node_state
|
474
482
|
node_cache_path = "#{base_path}/embedded/nodes/"
|
475
483
|
status = run_command("rm -rf #{node_cache_path}")
|
476
|
-
|
484
|
+
unless status.success?
|
477
485
|
log "Could not remove cached node state!"
|
478
486
|
exit 1
|
479
487
|
end
|
480
488
|
end
|
481
489
|
|
482
|
-
def run_chef(attr_location, args=
|
490
|
+
def run_chef(attr_location, args = "")
|
483
491
|
if @verbose
|
484
|
-
log_level = "-
|
492
|
+
log_level = "-l debug"
|
485
493
|
elsif @quiet
|
486
494
|
# null formatter is awfully quiet, so let them know we're doing something.
|
487
495
|
log "Reconfiguring #{display_name}."
|
488
|
-
log_level = "-
|
496
|
+
log_level = "-l fatal -F null"
|
489
497
|
else
|
490
498
|
log_level = ""
|
491
499
|
end
|
@@ -522,7 +530,7 @@ EOM
|
|
522
530
|
# any license to accept.
|
523
531
|
return unless File.exist?(project_license_path)
|
524
532
|
|
525
|
-
|
533
|
+
unless File.exist?(license_guard_file_path)
|
526
534
|
if override_accept || ask_license_acceptance
|
527
535
|
FileUtils.mkdir_p(data_path)
|
528
536
|
FileUtils.touch(license_guard_file_path)
|
@@ -536,7 +544,7 @@ EOM
|
|
536
544
|
def ask_license_acceptance
|
537
545
|
log "To use this software, you must agree to the terms of the software license agreement."
|
538
546
|
|
539
|
-
|
547
|
+
unless STDIN.tty?
|
540
548
|
log "Please view and accept the software license agreement, or pass --accept-license."
|
541
549
|
exit(1)
|
542
550
|
end
|
@@ -568,10 +576,10 @@ EOM
|
|
568
576
|
|
569
577
|
def tail(*args)
|
570
578
|
# find /var/log -type f -not -path '*/sasl/*' | grep -E -v '(lock|@|tgz|gzip)' | xargs tail --follow=name --retry
|
571
|
-
command = "find #{log_path}"
|
579
|
+
command = "find -L #{log_path}"
|
572
580
|
command << "/#{args[1]}" if args[1]
|
573
|
-
command <<
|
574
|
-
command << log_path_exclude.map { |path| " -not -path #{path}" }.join(
|
581
|
+
command << " -type f"
|
582
|
+
command << log_path_exclude.map { |path| " -not -path '#{path}'" }.join(" ")
|
575
583
|
command << " | grep -E -v '#{log_exclude}' | xargs tail --follow=name --retry"
|
576
584
|
|
577
585
|
system(command)
|
@@ -586,16 +594,17 @@ EOM
|
|
586
594
|
exit_status = 0
|
587
595
|
get_all_services.each do |service_name|
|
588
596
|
next if !service.nil? && service_name != service
|
597
|
+
|
589
598
|
if service_enabled?(service_name)
|
590
|
-
pidfile="#{sv_path}/#{service_name}/supervise/pid"
|
591
|
-
pid=File.read(pidfile).chomp if File.
|
599
|
+
pidfile = "#{sv_path}/#{service_name}/supervise/pid"
|
600
|
+
pid = File.read(pidfile).chomp if File.exist?(pidfile)
|
592
601
|
if pid.nil? || !is_integer?(pid)
|
593
602
|
log "could not find #{service_name} runit pidfile (service already stopped?), cannot attempt SIGKILL..."
|
594
603
|
status = run_command("#{base_path}/init/#{service_name} stop")
|
595
604
|
exit_status = status.exitstatus if exit_status == 0 && !status.success?
|
596
605
|
next
|
597
606
|
end
|
598
|
-
pgrp=get_pgrp_from_pid(pid)
|
607
|
+
pgrp = get_pgrp_from_pid(pid)
|
599
608
|
if pgrp.nil? || !is_integer?(pgrp)
|
600
609
|
log "could not find pgrp of pid #{pid} (not running?), cannot attempt SIGKILL..."
|
601
610
|
status = run_command("#{base_path}/init/#{service_name} stop")
|
@@ -603,14 +612,14 @@ EOM
|
|
603
612
|
next
|
604
613
|
end
|
605
614
|
run_command("#{base_path}/init/#{service_name} stop")
|
606
|
-
pids=get_pids_from_pgrp(pgrp)
|
607
|
-
|
615
|
+
pids = get_pids_from_pgrp(pgrp)
|
616
|
+
unless pids.empty?
|
608
617
|
log "found stuck pids still running in process group: #{pids}, sending SIGKILL" unless pids.empty?
|
609
618
|
sigkill_pgrp(pgrp)
|
610
619
|
end
|
611
620
|
else
|
612
621
|
log "#{service_name} disabled, not stopping"
|
613
|
-
exit_status =1
|
622
|
+
exit_status = 1
|
614
623
|
end
|
615
624
|
end
|
616
625
|
exit! exit_status
|
@@ -624,7 +633,7 @@ EOM
|
|
624
633
|
end
|
625
634
|
category_command_map.each do |category, commands|
|
626
635
|
# Remove "-" and replace with spaces in category and capalize for output
|
627
|
-
category_string = category.gsub("-", " ").split.map(&:capitalize).join(
|
636
|
+
category_string = category.gsub("-", " ").split.map(&:capitalize).join(" ")
|
628
637
|
log "#{category_string} Commands:\n"
|
629
638
|
|
630
639
|
# Print each command in this category
|
@@ -655,19 +664,19 @@ EOM
|
|
655
664
|
|
656
665
|
# If it begins with a '-', it is an option.
|
657
666
|
def is_option?(arg)
|
658
|
-
arg && arg[0] ==
|
667
|
+
arg && arg[0] == "-"
|
659
668
|
end
|
660
669
|
|
661
670
|
# retrieves the commmand from either the command_map
|
662
671
|
# or the category_command_map, if the command is not found
|
663
672
|
# return nil
|
664
673
|
def retrieve_command(command_to_run)
|
665
|
-
if command_map.
|
674
|
+
if command_map.key?(command_to_run)
|
666
675
|
command_map[command_to_run]
|
667
676
|
else
|
668
677
|
command = nil
|
669
678
|
category_command_map.each do |category, commands|
|
670
|
-
command = commands[command_to_run] if commands.
|
679
|
+
command = commands[command_to_run] if commands.key?(command_to_run)
|
671
680
|
end
|
672
681
|
# return the command, or nil if it wasn't found
|
673
682
|
command
|
@@ -681,11 +690,17 @@ EOM
|
|
681
690
|
def run(args)
|
682
691
|
# Ensure Omnibus related binaries are in the PATH
|
683
692
|
ENV["PATH"] = [File.join(base_path, "bin"),
|
684
|
-
File.join(base_path, "embedded","bin"),
|
685
|
-
ENV[
|
693
|
+
File.join(base_path, "embedded", "bin"),
|
694
|
+
ENV["PATH"]].join(":")
|
686
695
|
|
687
696
|
command_to_run = args[0]
|
688
697
|
|
698
|
+
## when --help is run as the command itself, we need to strip off the
|
699
|
+
## `--` to ensure the command maps correctly.
|
700
|
+
if command_to_run == "--help"
|
701
|
+
command_to_run = "help"
|
702
|
+
end
|
703
|
+
|
689
704
|
# This piece of code checks if the argument is an option. If it is,
|
690
705
|
# then it sets service to nil and adds the argument into the options
|
691
706
|
# argument. This is ugly. A better solution is having a proper parser.
|
@@ -721,6 +736,8 @@ EOM
|
|
721
736
|
@force_exit = false
|
722
737
|
exit_code = 0
|
723
738
|
|
739
|
+
run_global_pre_hooks
|
740
|
+
|
724
741
|
# Filter args to just command and service. If you are loading
|
725
742
|
# custom commands and need access to the command line argument,
|
726
743
|
# use ARGV directly.
|
@@ -747,6 +764,17 @@ EOM
|
|
747
764
|
end
|
748
765
|
end
|
749
766
|
|
767
|
+
def run_global_pre_hooks
|
768
|
+
@global_pre_hooks.each do |hook_name, method_name|
|
769
|
+
|
770
|
+
send(method_name)
|
771
|
+
rescue => e
|
772
|
+
$stderr.puts("Global pre-hook '#{hook_name}' failed with: '#{e.message}'")
|
773
|
+
exit(1)
|
774
|
+
|
775
|
+
end
|
776
|
+
end
|
777
|
+
|
750
778
|
# Below are some basic command hooks that do the right thing
|
751
779
|
# when a service is configured as external via [package][service
|
752
780
|
|
@@ -764,10 +792,11 @@ EOM
|
|
764
792
|
send(method, *args)
|
765
793
|
else
|
766
794
|
return true if args.empty?
|
795
|
+
|
767
796
|
if SV_COMMAND_NAMES.include? command
|
768
797
|
if service_external? args[0]
|
769
798
|
log error_external_service(command, args[0])
|
770
|
-
return false
|
799
|
+
return false
|
771
800
|
end
|
772
801
|
end
|
773
802
|
true
|
@@ -792,6 +821,7 @@ EOM
|
|
792
821
|
log_internal_service_header if service.nil?
|
793
822
|
true
|
794
823
|
end
|
824
|
+
|
795
825
|
# Status gets its own hook because each externalized service will
|
796
826
|
# have its own things to do in order to report status.
|
797
827
|
# As above, we may also include an output header to show that we're
|
@@ -842,22 +872,22 @@ EOM
|
|
842
872
|
# Add some output headers if we have external services enabled
|
843
873
|
def service_list_pre_hook
|
844
874
|
log_internal_service_header
|
845
|
-
|
875
|
+
true
|
846
876
|
end
|
847
877
|
|
848
878
|
# Capture external services in the output list as well.
|
849
879
|
def service_list_post_hook
|
850
880
|
log_external_service_header
|
851
881
|
external_services.each do |name, settings|
|
852
|
-
log " > #{name} on #{settings[
|
882
|
+
log " > #{name} on #{settings["vip"]}"
|
853
883
|
end
|
854
884
|
end
|
855
885
|
|
856
886
|
def error_external_service(command, service)
|
857
|
-
|
887
|
+
<<EOM
|
858
888
|
-------------------------------------------------------------------
|
859
889
|
The service #{service} is running externally and cannot be managed
|
860
|
-
vi chef-server-ctl. Please log into #{external_services[service][
|
890
|
+
vi chef-server-ctl. Please log into #{external_services[service]["vip"]}
|
861
891
|
to manage it directly.
|
862
892
|
-------------------------------------------------------------------
|
863
893
|
EOM
|
@@ -867,8 +897,8 @@ EOM
|
|
867
897
|
if message.class == String
|
868
898
|
message = message.split("\n")
|
869
899
|
end
|
870
|
-
spaces = " "*indent
|
871
|
-
message.map!{|line| "#{spaces}#{line.strip}"}
|
900
|
+
spaces = " " * indent
|
901
|
+
message.map! { |line| "#{spaces}#{line.strip}" }
|
872
902
|
message.join("\n")
|
873
903
|
end
|
874
904
|
|
@@ -876,6 +906,7 @@ EOM
|
|
876
906
|
# Don't decorate output unless we have
|
877
907
|
# external services to report on.
|
878
908
|
return if external_services.empty?
|
909
|
+
|
879
910
|
log "-------------------"
|
880
911
|
log " Internal Services "
|
881
912
|
log "-------------------"
|
@@ -883,6 +914,7 @@ EOM
|
|
883
914
|
|
884
915
|
def log_external_service_header
|
885
916
|
return if external_services.empty?
|
917
|
+
|
886
918
|
log "-------------------"
|
887
919
|
log " External Services "
|
888
920
|
log "-------------------"
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omnibus-ctl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Chef Software, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: chef-utils
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 16.5.54
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 16.5.54
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: chefstyle
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.2.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.2.0
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: rake
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,12 +89,13 @@ executables:
|
|
61
89
|
extensions: []
|
62
90
|
extra_rdoc_files: []
|
63
91
|
files:
|
64
|
-
-
|
92
|
+
- LICENSE
|
65
93
|
- bin/omnibus-ctl
|
66
94
|
- lib/omnibus-ctl.rb
|
67
95
|
- lib/omnibus-ctl/version.rb
|
68
96
|
homepage: http://github.com/chef/omnibus-ctl
|
69
|
-
licenses:
|
97
|
+
licenses:
|
98
|
+
- Apache-2.0
|
70
99
|
metadata: {}
|
71
100
|
post_install_message:
|
72
101
|
rdoc_options: []
|
@@ -76,15 +105,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
105
|
requirements:
|
77
106
|
- - ">="
|
78
107
|
- !ruby/object:Gem::Version
|
79
|
-
version: '
|
108
|
+
version: '2.6'
|
80
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
110
|
requirements:
|
82
111
|
- - ">="
|
83
112
|
- !ruby/object:Gem::Version
|
84
113
|
version: '0'
|
85
114
|
requirements: []
|
86
|
-
|
87
|
-
rubygems_version: 2.5.2
|
115
|
+
rubygems_version: 3.1.4
|
88
116
|
signing_key:
|
89
117
|
specification_version: 4
|
90
118
|
summary: Provides command line control for omnibus packages
|
data/README.md
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
# omnibus-ctl
|
2
|
-
|
3
|
-
[](https://travis-ci.org/chef/omnibus-ctl)
|
4
|
-
|
5
|
-
omnibus-ctl provides service control and configuration for omnibus packages.
|
6
|
-
|
7
|
-
For an introduction, please see this blog post [Omnibus-ctl: What is it and what can it do for you?](https://www.chef.io/blog/2015/05/26/omnibus-ctl-what-is-it-and-what-can-it-do-for-you/).
|
8
|
-
|
9
|
-
## Run the Tests!
|
10
|
-
|
11
|
-
There are tests in this repo that should be run before merging to master in the `spec` directory.
|
12
|
-
|
13
|
-
To run them, first install rspec via bundler:
|
14
|
-
|
15
|
-
```
|
16
|
-
bundle install
|
17
|
-
```
|
18
|
-
|
19
|
-
Then run the tests:
|
20
|
-
|
21
|
-
```
|
22
|
-
bin/rspec
|
23
|
-
```
|
24
|
-
|
25
|
-
## Framework API
|
26
|
-
|
27
|
-
There are two main functions you will use in your `*-ctl` project to add commands.
|
28
|
-
|
29
|
-
### add_command_under_category(string, string, string, int, ruby_block)
|
30
|
-
|
31
|
-
This method will add a new command to your ctl under a category, useful for grouping similar commands together logically in help output.
|
32
|
-
|
33
|
-
Input arguments:
|
34
|
-
|
35
|
-
1. Name of the command.
|
36
|
-
2. Category of the command. It should be string consisting of only characters and "-". If the category does not exist, it will be added. Default categories are "general" and "service-management" (if the latter is enabled).
|
37
|
-
3. Description. This will be outputted below the command name when the help command is run.
|
38
|
-
4. Arity. TODO: Due to current bug, this must be 2, I believe. We should fix this.
|
39
|
-
5. Ruby block. Ruby code to be executed when your command is run (arguments to that command will be passed into the block).
|
40
|
-
|
41
|
-
### add_command(string, string, int, ruby_block)
|
42
|
-
|
43
|
-
This method will add a new command to your ctl without a category. It will be displayed above all categories when the help command is called.
|
44
|
-
|
45
|
-
Input arguments are the same as `add_command_under_category` except 2 doesn't exist.
|
46
|
-
|
47
|
-
### Sample Output
|
48
|
-
|
49
|
-
```
|
50
|
-
# sample-ctl help
|
51
|
-
/opt/opscode/embedded/bin/sample-ctl: command (subcommand)
|
52
|
-
command-without-category
|
53
|
-
Here is an insightful description for the above command, added via add_command.
|
54
|
-
another-command-without-category
|
55
|
-
Yet another description.
|
56
|
-
Some Category Of Commands:
|
57
|
-
command-with-category
|
58
|
-
Exciting description of command added via add_command_under_category.
|
59
|
-
better-command-with-category
|
60
|
-
You get the idea.
|
61
|
-
Another Category:
|
62
|
-
command-with-better-category
|
63
|
-
I'm not just going to copy-pasta above example descriptions.
|
64
|
-
better-command-with-better-category
|
65
|
-
I'm running out of ideas.
|
66
|
-
```
|
67
|
-
|
68
|
-
If you only use `add_command_under_category` to add your custom commands, everything will be outputted under a category.
|
69
|
-
|
70
|
-
## Releasing
|
71
|
-
|
72
|
-
*NOTE: Versions prior to 0.3.6 do not use a "v" prefix for their tags. Current
|
73
|
-
versions do.*
|
74
|
-
|
75
|
-
* Update the version in lib/omnibus-ctl/version.rb.
|
76
|
-
* Update the [Change log](CHANGELOG.md).
|
77
|
-
* Commit those changes.
|
78
|
-
* Make sure you are an owner of the
|
79
|
-
[omnibus-ctl gem on RubyGems.org](https://rubygems.org/gems/omnibus-ctl). If
|
80
|
-
you aren't, contact one of the owners to be added.
|
81
|
-
* `rake release`. This will tag the version, push it to GitHub and RubyGems.
|
82
|
-
|
83
|
-
## License
|
84
|
-
|
85
|
-
See the LICENSE file for details.
|
86
|
-
|
87
|
-
Copyright: Copyright (c) 2012-2015 Chef Software, Inc.
|
88
|
-
License: Apache License, Version 2.0
|
89
|
-
|
90
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
91
|
-
you may not use this file except in compliance with the License.
|
92
|
-
You may obtain a copy of the License at
|
93
|
-
|
94
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
95
|
-
|
96
|
-
Unless required by applicable law or agreed to in writing, software
|
97
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
98
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
99
|
-
See the License for the specific language governing permissions and
|
100
|
-
limitations under the License.
|