omnibus-ctl 0.6.0 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- 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 +114 -112
- metadata +19 -6
- data/README.md +0 -121
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c215684c3b196f84c40859cf894ce09d2a0a070d43042b0d59193cd784af4754
|
4
|
+
data.tar.gz: ee14af6d515213397148b5c7457c8de3de5897adbee7ee17bf8318eedfbed12b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fea679725447c7a7bbce01f1f06fc54a63bd6daa1b8db79baf0cb0522caf5f93cd17673c732404917af1330a59a88d24121e6547a7b36bcbe06dea26a813520d
|
7
|
+
data.tar.gz: 0e1de00e1f4226e1acbd1ecaee5abf622fdd3526a8fba794916f90a883b15546de4ef96bbb0b03a1eb402ad7cccc61e7295971989abd74785625e0682cda0a1e
|
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,21 @@
|
|
15
15
|
#
|
16
16
|
|
17
17
|
require "omnibus-ctl/version"
|
18
|
-
require
|
19
|
-
require
|
18
|
+
require "json" unless defined?(JSON)
|
19
|
+
require "fileutils" unless defined?(FileUtils)
|
20
20
|
|
21
21
|
# For license checks
|
22
|
-
require
|
23
|
-
require
|
22
|
+
require "io/console"
|
23
|
+
require "io/wait"
|
24
24
|
|
25
25
|
module Omnibus
|
26
26
|
class Ctl
|
27
27
|
|
28
|
-
File
|
28
|
+
File.umask(022)
|
29
29
|
|
30
|
-
SV_COMMAND_NAMES = %w
|
30
|
+
SV_COMMAND_NAMES = %w{status up down once pause cont hup alarm int quit
|
31
31
|
term kill start stop restart shutdown force-stop
|
32
|
-
force-reload force-restart force-shutdown check usr1 usr2
|
32
|
+
force-reload force-restart force-shutdown check usr1 usr2}.freeze
|
33
33
|
|
34
34
|
attr_accessor :name, :display_name, :log_exclude, :base_path, :sv_path,
|
35
35
|
:service_path, :etc_path, :data_path, :log_path, :command_map, :category_command_map,
|
@@ -37,8 +37,7 @@ module Omnibus
|
|
37
37
|
|
38
38
|
attr_reader :backup_dir, :exe_name
|
39
39
|
|
40
|
-
|
41
|
-
def initialize(name, merge_service_commands=true, disp_name = nil)
|
40
|
+
def initialize(name, merge_service_commands = true, disp_name = nil)
|
42
41
|
@name = name
|
43
42
|
@service_commands = merge_service_commands
|
44
43
|
@display_name = disp_name || name
|
@@ -48,8 +47,8 @@ module Omnibus
|
|
48
47
|
@log_path = "/var/log/#{name}"
|
49
48
|
@data_path = "/var/opt/#{name}"
|
50
49
|
@etc_path = "/etc/#{name}"
|
51
|
-
@log_exclude =
|
52
|
-
@log_path_exclude = [
|
50
|
+
@log_exclude = "(config|lock|@|bz2|gz|gzip|tbz2|tgz|txz|xz|zip)"
|
51
|
+
@log_path_exclude = ["*/sasl/*"]
|
53
52
|
@fh_output = STDOUT
|
54
53
|
@kill_users = []
|
55
54
|
@verbose = false
|
@@ -61,101 +60,101 @@ module Omnibus
|
|
61
60
|
# TODO(ssd) 2017-03-28: Set SVDIR explicitly. Once we fix a bug
|
62
61
|
# in our debian support, where we rely on system-installed
|
63
62
|
# runit, we can likely change this back to ENV.delete("SVDIR")
|
64
|
-
ENV[
|
63
|
+
ENV["SVDIR"] = service_path
|
65
64
|
|
66
65
|
# backwards compat command map that does not have categories
|
67
|
-
@command_map = {
|
66
|
+
@command_map = {}
|
68
67
|
|
69
68
|
# categoired commands that we want by default
|
70
69
|
@category_command_map = {
|
71
70
|
"general" => {
|
72
71
|
"show-config" => {
|
73
|
-
:
|
74
|
-
:
|
72
|
+
desc: "Show the configuration that would be generated by reconfigure.",
|
73
|
+
arity: 1,
|
75
74
|
},
|
76
75
|
"reconfigure" => {
|
77
|
-
:
|
78
|
-
:
|
76
|
+
desc: "Reconfigure the application.",
|
77
|
+
arity: 2,
|
79
78
|
},
|
80
79
|
"cleanse" => {
|
81
|
-
:
|
82
|
-
:
|
80
|
+
desc: "Delete *all* #{display_name} data, and start from scratch.",
|
81
|
+
arity: 2,
|
83
82
|
},
|
84
83
|
"uninstall" => {
|
85
|
-
:
|
86
|
-
:
|
84
|
+
arity: 1,
|
85
|
+
desc: "Kill all processes and uninstall the process supervisor (data will be preserved).",
|
87
86
|
},
|
88
87
|
"help" => {
|
89
|
-
:
|
90
|
-
:
|
91
|
-
}
|
92
|
-
}
|
88
|
+
arity: 1,
|
89
|
+
desc: "Print this help message.",
|
90
|
+
},
|
91
|
+
},
|
93
92
|
}
|
94
93
|
service_command_map = {
|
95
94
|
"service-management" => {
|
96
95
|
"service-list" => {
|
97
|
-
:
|
98
|
-
:
|
96
|
+
arity: 1,
|
97
|
+
desc: "List all the services (enabled services appear with a *.)",
|
99
98
|
},
|
100
99
|
"status" => {
|
101
|
-
:
|
102
|
-
:
|
100
|
+
desc: "Show the status of all the services.",
|
101
|
+
arity: 2,
|
103
102
|
},
|
104
103
|
"tail" => {
|
105
|
-
:
|
106
|
-
:
|
104
|
+
desc: "Watch the service logs of all enabled services.",
|
105
|
+
arity: 2,
|
107
106
|
},
|
108
107
|
"start" => {
|
109
|
-
:
|
110
|
-
:
|
108
|
+
desc: "Start services if they are down, and restart them if they stop.",
|
109
|
+
arity: 2,
|
111
110
|
},
|
112
111
|
"stop" => {
|
113
|
-
:
|
114
|
-
:
|
112
|
+
desc: "Stop the services, and do not restart them.",
|
113
|
+
arity: 2,
|
115
114
|
},
|
116
115
|
"restart" => {
|
117
|
-
:
|
118
|
-
:
|
116
|
+
desc: "Stop the services if they are running, then start them again.",
|
117
|
+
arity: 2,
|
119
118
|
},
|
120
119
|
"once" => {
|
121
|
-
:
|
122
|
-
:
|
120
|
+
desc: "Start the services if they are down. Do not restart them if they stop.",
|
121
|
+
arity: 2,
|
123
122
|
},
|
124
123
|
"hup" => {
|
125
|
-
:
|
126
|
-
:
|
124
|
+
desc: "Send the services a HUP.",
|
125
|
+
arity: 2,
|
127
126
|
},
|
128
127
|
"term" => {
|
129
|
-
:
|
130
|
-
:
|
128
|
+
desc: "Send the services a TERM.",
|
129
|
+
arity: 2,
|
131
130
|
},
|
132
131
|
"int" => {
|
133
|
-
:
|
134
|
-
:
|
132
|
+
desc: "Send the services an INT.",
|
133
|
+
arity: 2,
|
135
134
|
},
|
136
135
|
"kill" => {
|
137
|
-
:
|
138
|
-
:
|
136
|
+
desc: "Send the services a KILL.",
|
137
|
+
arity: 2,
|
139
138
|
},
|
140
139
|
"graceful-kill" => {
|
141
|
-
:
|
142
|
-
:
|
140
|
+
desc: "Attempt a graceful stop, then SIGKILL the entire process group.",
|
141
|
+
arity: 2,
|
143
142
|
},
|
144
143
|
"usr1" => {
|
145
|
-
:
|
146
|
-
:
|
144
|
+
desc: "Send the services a USR1.",
|
145
|
+
arity: 2,
|
147
146
|
},
|
148
147
|
"usr2" => {
|
149
|
-
:
|
150
|
-
:
|
151
|
-
}
|
152
|
-
}
|
148
|
+
desc: "Send the services a USR2.",
|
149
|
+
arity: 2,
|
150
|
+
},
|
151
|
+
},
|
153
152
|
}
|
154
153
|
@category_command_map.merge!(service_command_map) if service_commands?
|
155
154
|
end
|
156
155
|
|
157
156
|
def self.to_method_name(name)
|
158
|
-
name.gsub(/-/,
|
157
|
+
name.gsub(/-/, "_").to_sym
|
159
158
|
end
|
160
159
|
|
161
160
|
def to_method_name(name)
|
@@ -189,7 +188,7 @@ module Omnibus
|
|
189
188
|
end
|
190
189
|
|
191
190
|
def load_file(filepath)
|
192
|
-
eval(IO.read(filepath), nil, filepath, 1)
|
191
|
+
eval(IO.read(filepath), nil, filepath, 1) # rubocop: disable Security/Eval
|
193
192
|
end
|
194
193
|
|
195
194
|
def add_command(name, description, arity = 1, &block)
|
@@ -220,17 +219,17 @@ module Omnibus
|
|
220
219
|
end
|
221
220
|
|
222
221
|
def get_pgrp_from_pid(pid)
|
223
|
-
ps
|
222
|
+
ps = `which ps`.chomp
|
224
223
|
`#{ps} -p #{pid} -o pgrp=`.chomp
|
225
224
|
end
|
226
225
|
|
227
226
|
def get_pids_from_pgrp(pgrp)
|
228
|
-
pgrep
|
227
|
+
pgrep = `which pgrep`.chomp
|
229
228
|
`#{pgrep} -g #{pgrp}`.split(/\n/).join(" ")
|
230
229
|
end
|
231
230
|
|
232
231
|
def sigkill_pgrp(pgrp)
|
233
|
-
pkill
|
232
|
+
pkill = `which pkill`.chomp
|
234
233
|
run_command("#{pkill} -9 -g #{pgrp}")
|
235
234
|
end
|
236
235
|
|
@@ -251,26 +250,26 @@ module Omnibus
|
|
251
250
|
def cleanup_procs_and_nuke(filestr, calling_method = nil)
|
252
251
|
run_sv_command("stop")
|
253
252
|
|
254
|
-
FileUtils.rm_f("/etc/init/#{name}-runsvdir.conf") if File.
|
255
|
-
run_command("egrep -v '#{base_path}/embedded/bin/runsvdir-start' /etc/inittab > /etc/inittab.new && mv /etc/inittab.new /etc/inittab") if File.
|
253
|
+
FileUtils.rm_f("/etc/init/#{name}-runsvdir.conf") if File.exist?("/etc/init/#{name}-runsvdir.conf")
|
254
|
+
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")
|
256
255
|
run_command("kill -1 1")
|
257
256
|
|
258
257
|
@backup_dir = Time.now.strftime("/root/#{name}-cleanse-%FT%R")
|
259
258
|
|
260
|
-
FileUtils.mkdir_p("/root") unless File.
|
259
|
+
FileUtils.mkdir_p("/root") unless File.exist?("/root")
|
261
260
|
FileUtils.rm_rf(backup_dir)
|
262
|
-
FileUtils.cp_r(etc_path, backup_dir) if File.
|
261
|
+
FileUtils.cp_r(etc_path, backup_dir) if File.exist?(etc_path)
|
263
262
|
run_command("rm -rf #{filestr}")
|
264
263
|
graceful_kill
|
265
264
|
|
266
265
|
log "Terminating processes running under application users. This will take a few seconds."
|
267
|
-
run_command("pkill -HUP -u #{kill_users.join(
|
266
|
+
run_command("pkill -HUP -u #{kill_users.join(",")}") if kill_users.length > 0
|
268
267
|
run_command("pkill -HUP -f 'runsvdir -P #{service_path}'")
|
269
268
|
sleep 3
|
270
|
-
run_command("pkill -TERM -u #{kill_users.join(
|
269
|
+
run_command("pkill -TERM -u #{kill_users.join(",")}") if kill_users.length > 0
|
271
270
|
run_command("pkill -TERM -f 'runsvdir -P #{service_path}'")
|
272
271
|
sleep 3
|
273
|
-
run_command("pkill -KILL -u #{kill_users.join(
|
272
|
+
run_command("pkill -KILL -u #{kill_users.join(",")}") if kill_users.length > 0
|
274
273
|
run_command("pkill -KILL -f 'runsvdir -P #{service_path}'")
|
275
274
|
|
276
275
|
get_all_services.each do |die_daemon_die|
|
@@ -294,13 +293,13 @@ module Omnibus
|
|
294
293
|
This command will delete *all* local configuration, log, and
|
295
294
|
variable data associated with #{display_name}.
|
296
295
|
EOM
|
297
|
-
if
|
296
|
+
if with_external
|
298
297
|
log <<EOM
|
299
298
|
This will also delete externally hosted #{display_name} data.
|
300
299
|
This means that any service you have configured as 'external'
|
301
300
|
will have any #{display_name} permanently deleted.
|
302
301
|
EOM
|
303
|
-
elsif
|
302
|
+
elsif not external_services.empty?
|
304
303
|
log <<EOM
|
305
304
|
|
306
305
|
Important note: If you also wish to delete externally hosted #{display_name}
|
@@ -332,9 +331,8 @@ EOM
|
|
332
331
|
cleanup_procs_and_nuke("#{service_path}/* /tmp/opt #{data_path} #{etc_path} #{log_path}", "cleanse")
|
333
332
|
end
|
334
333
|
|
335
|
-
|
336
334
|
def get_all_services_files
|
337
|
-
Dir[File.join(sv_path,
|
335
|
+
Dir[File.join(sv_path, "*")]
|
338
336
|
end
|
339
337
|
|
340
338
|
def get_all_services
|
@@ -345,7 +343,7 @@ EOM
|
|
345
343
|
File.symlink?("#{service_path}/#{service_name}")
|
346
344
|
end
|
347
345
|
|
348
|
-
def run_sv_command(sv_cmd, service=nil)
|
346
|
+
def run_sv_command(sv_cmd, service = nil)
|
349
347
|
exit_status = 0
|
350
348
|
sv_cmd = "1" if sv_cmd == "usr1"
|
351
349
|
sv_cmd = "2" if sv_cmd == "usr2"
|
@@ -398,7 +396,7 @@ EOM
|
|
398
396
|
end
|
399
397
|
|
400
398
|
# All other services respond normally to p-c-c * commands
|
401
|
-
|
399
|
+
true
|
402
400
|
end
|
403
401
|
|
404
402
|
# removed services are configured via the attributes file in
|
@@ -439,24 +437,23 @@ EOM
|
|
439
437
|
|
440
438
|
# returns nil when chef-server-running.json does not exist
|
441
439
|
def running_config
|
442
|
-
@running_config ||=
|
443
|
-
|
444
|
-
|
445
|
-
end
|
446
|
-
end
|
440
|
+
@running_config ||= if File.exist?("#{etc_path}/chef-server-running.json")
|
441
|
+
JSON.parse(File.read("#{etc_path}/chef-server-running.json"))
|
442
|
+
end
|
447
443
|
end
|
448
444
|
|
449
445
|
# Helper function that returns the hash of config hashes that have the key 'external' : true
|
450
446
|
# in the running config. If none exist it will return an empty hash.
|
451
447
|
def external_services
|
452
|
-
@external_services
|
448
|
+
@external_services ||= running_package_config.select { |k, v| v.class == Hash and v["external"] == true }
|
453
449
|
end
|
454
450
|
|
455
451
|
# Helper function that returns true if an external service entry exists for
|
456
452
|
# the named service
|
457
453
|
def service_external?(service)
|
458
454
|
return false if service.nil?
|
459
|
-
|
455
|
+
|
456
|
+
external_services.key? service
|
460
457
|
end
|
461
458
|
|
462
459
|
# Gives package config from the running_config.
|
@@ -464,7 +461,7 @@ EOM
|
|
464
461
|
# reference a valid key, this will return an empty hash
|
465
462
|
def running_package_config
|
466
463
|
if (cfg = running_config)
|
467
|
-
cfg[package_name.gsub(/-/,
|
464
|
+
cfg[package_name.gsub(/-/, "_")] || {}
|
468
465
|
else
|
469
466
|
{}
|
470
467
|
end
|
@@ -481,13 +478,13 @@ EOM
|
|
481
478
|
def remove_old_node_state
|
482
479
|
node_cache_path = "#{base_path}/embedded/nodes/"
|
483
480
|
status = run_command("rm -rf #{node_cache_path}")
|
484
|
-
|
481
|
+
unless status.success?
|
485
482
|
log "Could not remove cached node state!"
|
486
483
|
exit 1
|
487
484
|
end
|
488
485
|
end
|
489
486
|
|
490
|
-
def run_chef(attr_location, args=
|
487
|
+
def run_chef(attr_location, args = "")
|
491
488
|
if @verbose
|
492
489
|
log_level = "-l debug"
|
493
490
|
elsif @quiet
|
@@ -530,7 +527,7 @@ EOM
|
|
530
527
|
# any license to accept.
|
531
528
|
return unless File.exist?(project_license_path)
|
532
529
|
|
533
|
-
|
530
|
+
unless File.exist?(license_guard_file_path)
|
534
531
|
if override_accept || ask_license_acceptance
|
535
532
|
FileUtils.mkdir_p(data_path)
|
536
533
|
FileUtils.touch(license_guard_file_path)
|
@@ -544,7 +541,7 @@ EOM
|
|
544
541
|
def ask_license_acceptance
|
545
542
|
log "To use this software, you must agree to the terms of the software license agreement."
|
546
543
|
|
547
|
-
|
544
|
+
unless STDIN.tty?
|
548
545
|
log "Please view and accept the software license agreement, or pass --accept-license."
|
549
546
|
exit(1)
|
550
547
|
end
|
@@ -578,8 +575,8 @@ EOM
|
|
578
575
|
# find /var/log -type f -not -path '*/sasl/*' | grep -E -v '(lock|@|tgz|gzip)' | xargs tail --follow=name --retry
|
579
576
|
command = "find -L #{log_path}"
|
580
577
|
command << "/#{args[1]}" if args[1]
|
581
|
-
command <<
|
582
|
-
command << log_path_exclude.map { |path| " -not -path '#{path}'" }.join(
|
578
|
+
command << " -type f"
|
579
|
+
command << log_path_exclude.map { |path| " -not -path '#{path}'" }.join(" ")
|
583
580
|
command << " | grep -E -v '#{log_exclude}' | xargs tail --follow=name --retry"
|
584
581
|
|
585
582
|
system(command)
|
@@ -594,16 +591,17 @@ EOM
|
|
594
591
|
exit_status = 0
|
595
592
|
get_all_services.each do |service_name|
|
596
593
|
next if !service.nil? && service_name != service
|
594
|
+
|
597
595
|
if service_enabled?(service_name)
|
598
|
-
pidfile="#{sv_path}/#{service_name}/supervise/pid"
|
599
|
-
pid=File.read(pidfile).chomp if File.
|
596
|
+
pidfile = "#{sv_path}/#{service_name}/supervise/pid"
|
597
|
+
pid = File.read(pidfile).chomp if File.exist?(pidfile)
|
600
598
|
if pid.nil? || !is_integer?(pid)
|
601
599
|
log "could not find #{service_name} runit pidfile (service already stopped?), cannot attempt SIGKILL..."
|
602
600
|
status = run_command("#{base_path}/init/#{service_name} stop")
|
603
601
|
exit_status = status.exitstatus if exit_status == 0 && !status.success?
|
604
602
|
next
|
605
603
|
end
|
606
|
-
pgrp=get_pgrp_from_pid(pid)
|
604
|
+
pgrp = get_pgrp_from_pid(pid)
|
607
605
|
if pgrp.nil? || !is_integer?(pgrp)
|
608
606
|
log "could not find pgrp of pid #{pid} (not running?), cannot attempt SIGKILL..."
|
609
607
|
status = run_command("#{base_path}/init/#{service_name} stop")
|
@@ -611,14 +609,14 @@ EOM
|
|
611
609
|
next
|
612
610
|
end
|
613
611
|
run_command("#{base_path}/init/#{service_name} stop")
|
614
|
-
pids=get_pids_from_pgrp(pgrp)
|
615
|
-
|
612
|
+
pids = get_pids_from_pgrp(pgrp)
|
613
|
+
unless pids.empty?
|
616
614
|
log "found stuck pids still running in process group: #{pids}, sending SIGKILL" unless pids.empty?
|
617
615
|
sigkill_pgrp(pgrp)
|
618
616
|
end
|
619
617
|
else
|
620
618
|
log "#{service_name} disabled, not stopping"
|
621
|
-
exit_status =1
|
619
|
+
exit_status = 1
|
622
620
|
end
|
623
621
|
end
|
624
622
|
exit! exit_status
|
@@ -632,7 +630,7 @@ EOM
|
|
632
630
|
end
|
633
631
|
category_command_map.each do |category, commands|
|
634
632
|
# Remove "-" and replace with spaces in category and capalize for output
|
635
|
-
category_string = category.gsub("-", " ").split.map(&:capitalize).join(
|
633
|
+
category_string = category.gsub("-", " ").split.map(&:capitalize).join(" ")
|
636
634
|
log "#{category_string} Commands:\n"
|
637
635
|
|
638
636
|
# Print each command in this category
|
@@ -663,19 +661,19 @@ EOM
|
|
663
661
|
|
664
662
|
# If it begins with a '-', it is an option.
|
665
663
|
def is_option?(arg)
|
666
|
-
arg && arg[0] ==
|
664
|
+
arg && arg[0] == "-"
|
667
665
|
end
|
668
666
|
|
669
667
|
# retrieves the commmand from either the command_map
|
670
668
|
# or the category_command_map, if the command is not found
|
671
669
|
# return nil
|
672
670
|
def retrieve_command(command_to_run)
|
673
|
-
if command_map.
|
671
|
+
if command_map.key?(command_to_run)
|
674
672
|
command_map[command_to_run]
|
675
673
|
else
|
676
674
|
command = nil
|
677
675
|
category_command_map.each do |category, commands|
|
678
|
-
command = commands[command_to_run] if commands.
|
676
|
+
command = commands[command_to_run] if commands.key?(command_to_run)
|
679
677
|
end
|
680
678
|
# return the command, or nil if it wasn't found
|
681
679
|
command
|
@@ -689,8 +687,8 @@ EOM
|
|
689
687
|
def run(args)
|
690
688
|
# Ensure Omnibus related binaries are in the PATH
|
691
689
|
ENV["PATH"] = [File.join(base_path, "bin"),
|
692
|
-
File.join(base_path, "embedded","bin"),
|
693
|
-
ENV[
|
690
|
+
File.join(base_path, "embedded", "bin"),
|
691
|
+
ENV["PATH"]].join(":")
|
694
692
|
|
695
693
|
command_to_run = args[0]
|
696
694
|
|
@@ -765,12 +763,12 @@ EOM
|
|
765
763
|
|
766
764
|
def run_global_pre_hooks
|
767
765
|
@global_pre_hooks.each do |hook_name, method_name|
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
766
|
+
|
767
|
+
send(method_name)
|
768
|
+
rescue => e
|
769
|
+
$stderr.puts("Global pre-hook '#{hook_name}' failed with: '#{e.message}'")
|
770
|
+
exit(1)
|
771
|
+
|
774
772
|
end
|
775
773
|
end
|
776
774
|
|
@@ -791,10 +789,11 @@ EOM
|
|
791
789
|
send(method, *args)
|
792
790
|
else
|
793
791
|
return true if args.empty?
|
792
|
+
|
794
793
|
if SV_COMMAND_NAMES.include? command
|
795
794
|
if service_external? args[0]
|
796
795
|
log error_external_service(command, args[0])
|
797
|
-
return false
|
796
|
+
return false
|
798
797
|
end
|
799
798
|
end
|
800
799
|
true
|
@@ -819,6 +818,7 @@ EOM
|
|
819
818
|
log_internal_service_header if service.nil?
|
820
819
|
true
|
821
820
|
end
|
821
|
+
|
822
822
|
# Status gets its own hook because each externalized service will
|
823
823
|
# have its own things to do in order to report status.
|
824
824
|
# As above, we may also include an output header to show that we're
|
@@ -869,22 +869,22 @@ EOM
|
|
869
869
|
# Add some output headers if we have external services enabled
|
870
870
|
def service_list_pre_hook
|
871
871
|
log_internal_service_header
|
872
|
-
|
872
|
+
true
|
873
873
|
end
|
874
874
|
|
875
875
|
# Capture external services in the output list as well.
|
876
876
|
def service_list_post_hook
|
877
877
|
log_external_service_header
|
878
878
|
external_services.each do |name, settings|
|
879
|
-
log " > #{name} on #{settings[
|
879
|
+
log " > #{name} on #{settings["vip"]}"
|
880
880
|
end
|
881
881
|
end
|
882
882
|
|
883
883
|
def error_external_service(command, service)
|
884
|
-
|
884
|
+
<<EOM
|
885
885
|
-------------------------------------------------------------------
|
886
886
|
The service #{service} is running externally and cannot be managed
|
887
|
-
vi chef-server-ctl. Please log into #{external_services[service][
|
887
|
+
vi chef-server-ctl. Please log into #{external_services[service]["vip"]}
|
888
888
|
to manage it directly.
|
889
889
|
-------------------------------------------------------------------
|
890
890
|
EOM
|
@@ -894,8 +894,8 @@ EOM
|
|
894
894
|
if message.class == String
|
895
895
|
message = message.split("\n")
|
896
896
|
end
|
897
|
-
spaces = " "*indent
|
898
|
-
message.map!{|line| "#{spaces}#{line.strip}"}
|
897
|
+
spaces = " " * indent
|
898
|
+
message.map! { |line| "#{spaces}#{line.strip}" }
|
899
899
|
message.join("\n")
|
900
900
|
end
|
901
901
|
|
@@ -903,6 +903,7 @@ EOM
|
|
903
903
|
# Don't decorate output unless we have
|
904
904
|
# external services to report on.
|
905
905
|
return if external_services.empty?
|
906
|
+
|
906
907
|
log "-------------------"
|
907
908
|
log " Internal Services "
|
908
909
|
log "-------------------"
|
@@ -910,6 +911,7 @@ EOM
|
|
910
911
|
|
911
912
|
def log_external_service_header
|
912
913
|
return if external_services.empty?
|
914
|
+
|
913
915
|
log "-------------------"
|
914
916
|
log " External Services "
|
915
917
|
log "-------------------"
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omnibus-ctl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
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: 2021-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: chefstyle
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.9
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.9
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rake
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,7 +75,7 @@ executables:
|
|
61
75
|
extensions: []
|
62
76
|
extra_rdoc_files: []
|
63
77
|
files:
|
64
|
-
-
|
78
|
+
- LICENSE
|
65
79
|
- bin/omnibus-ctl
|
66
80
|
- lib/omnibus-ctl.rb
|
67
81
|
- lib/omnibus-ctl/version.rb
|
@@ -77,15 +91,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
91
|
requirements:
|
78
92
|
- - ">="
|
79
93
|
- !ruby/object:Gem::Version
|
80
|
-
version: '
|
94
|
+
version: '2.6'
|
81
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
96
|
requirements:
|
83
97
|
- - ">="
|
84
98
|
- !ruby/object:Gem::Version
|
85
99
|
version: '0'
|
86
100
|
requirements: []
|
87
|
-
|
88
|
-
rubygems_version: 2.6.13
|
101
|
+
rubygems_version: 3.1.4
|
89
102
|
signing_key:
|
90
103
|
specification_version: 4
|
91
104
|
summary: Provides command line control for omnibus packages
|
data/README.md
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
# omnibus-ctl
|
2
|
-
|
3
|
-
[![Build Status Master](https://travis-ci.org/chef/omnibus-ctl.svg?branch=master)](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
|
-
## Command 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
|
-
## Pre-hook API
|
71
|
-
|
72
|
-
### add_global_pre_hook(string, ruby_block)
|
73
|
-
|
74
|
-
This method will add a global pre-hook block that will be executed before any
|
75
|
-
*-ctl command is run. If the pre-hook raises an exception it will cause an early
|
76
|
-
exit before the command is run.
|
77
|
-
|
78
|
-
Input Arguments:
|
79
|
-
|
80
|
-
1. Name of the hook
|
81
|
-
1. Ruby block of the code to be executed.
|
82
|
-
|
83
|
-
### Sample
|
84
|
-
|
85
|
-
```ruby
|
86
|
-
add_global_pre_hook "ensure that the user is always root" do
|
87
|
-
raise "You must run this command as root" unless Process.uid == 0
|
88
|
-
end
|
89
|
-
```
|
90
|
-
|
91
|
-
## Releasing
|
92
|
-
|
93
|
-
*NOTE: Versions prior to 0.3.6 do not use a "v" prefix for their tags. Current
|
94
|
-
versions do.*
|
95
|
-
|
96
|
-
* Update the version in lib/omnibus-ctl/version.rb.
|
97
|
-
* Update the [Change log](CHANGELOG.md).
|
98
|
-
* Commit those changes.
|
99
|
-
* Make sure you are an owner of the
|
100
|
-
[omnibus-ctl gem on RubyGems.org](https://rubygems.org/gems/omnibus-ctl). If
|
101
|
-
you aren't, contact one of the owners to be added.
|
102
|
-
* `rake release`. This will tag the version, push it to GitHub and RubyGems.
|
103
|
-
|
104
|
-
## License
|
105
|
-
|
106
|
-
See the LICENSE file for details.
|
107
|
-
|
108
|
-
Copyright: Copyright (c) 2012-2015 Chef Software, Inc.
|
109
|
-
License: Apache License, Version 2.0
|
110
|
-
|
111
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
112
|
-
you may not use this file except in compliance with the License.
|
113
|
-
You may obtain a copy of the License at
|
114
|
-
|
115
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
116
|
-
|
117
|
-
Unless required by applicable law or agreed to in writing, software
|
118
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
119
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
120
|
-
See the License for the specific language governing permissions and
|
121
|
-
limitations under the License.
|