omnibus-ctl 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -1
- data/lib/omnibus-ctl.rb +44 -17
- data/lib/omnibus-ctl/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7124151190ecb3203434afe79f6f705cc92006ac
|
4
|
+
data.tar.gz: 2054e06087ef69abeb032265e01fd32dfc5db730
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd94929d628f632dd24ab41e36e3efba988ce2a0c7193172e1089d48136bbe108a997cc42a5438fd0165a8f3ce469911ddabae3c2965da002561a8084fb581b2
|
7
|
+
data.tar.gz: 3ce02e9da7978e6d40837d7ccf7e141a67b9447b9837e966b7b1db8d0d66a1007c1e36cf9283a383d9ee384ba41bfe8cd9d1026ff5795f9751dfae3d221cef65
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ Then run the tests:
|
|
22
22
|
bin/rspec
|
23
23
|
```
|
24
24
|
|
25
|
-
##
|
25
|
+
## Command API
|
26
26
|
|
27
27
|
There are two main functions you will use in your `*-ctl` project to add commands.
|
28
28
|
|
@@ -67,6 +67,27 @@ Another Category:
|
|
67
67
|
|
68
68
|
If you only use `add_command_under_category` to add your custom commands, everything will be outputted under a category.
|
69
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
|
+
|
70
91
|
## Releasing
|
71
92
|
|
72
93
|
*NOTE: Versions prior to 0.3.6 do not use a "v" prefix for their tags. Current
|
data/lib/omnibus-ctl.rb
CHANGED
@@ -27,7 +27,7 @@ module Omnibus
|
|
27
27
|
|
28
28
|
File::umask(022)
|
29
29
|
|
30
|
-
SV_COMMAND_NAMES = %w[status up down once pause cont hup alarm
|
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
32
|
force-reload force-restart force-shutdown check usr1 usr2]
|
33
33
|
|
@@ -56,6 +56,12 @@ module Omnibus
|
|
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
67
|
@command_map = { }
|
@@ -151,6 +157,7 @@ module Omnibus
|
|
151
157
|
def self.to_method_name(name)
|
152
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
|
@@ -185,21 +192,22 @@ module Omnibus
|
|
185
192
|
eval(IO.read(filepath), nil, filepath, 1)
|
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)
|
@@ -481,11 +489,11 @@ EOM
|
|
481
489
|
|
482
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
|
@@ -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
581
|
command << ' -type f'
|
574
|
-
command << log_path_exclude.map { |path| " -not -path #{path}" }.join(' ')
|
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)
|
@@ -686,6 +694,12 @@ EOM
|
|
686
694
|
|
687
695
|
command_to_run = args[0]
|
688
696
|
|
697
|
+
## when --help is run as the command itself, we need to strip off the
|
698
|
+
## `--` to ensure the command maps correctly.
|
699
|
+
if command_to_run == "--help"
|
700
|
+
command_to_run = "help"
|
701
|
+
end
|
702
|
+
|
689
703
|
# This piece of code checks if the argument is an option. If it is,
|
690
704
|
# then it sets service to nil and adds the argument into the options
|
691
705
|
# argument. This is ugly. A better solution is having a proper parser.
|
@@ -721,6 +735,8 @@ EOM
|
|
721
735
|
@force_exit = false
|
722
736
|
exit_code = 0
|
723
737
|
|
738
|
+
run_global_pre_hooks
|
739
|
+
|
724
740
|
# Filter args to just command and service. If you are loading
|
725
741
|
# custom commands and need access to the command line argument,
|
726
742
|
# use ARGV directly.
|
@@ -747,6 +763,17 @@ EOM
|
|
747
763
|
end
|
748
764
|
end
|
749
765
|
|
766
|
+
def run_global_pre_hooks
|
767
|
+
@global_pre_hooks.each do |hook_name, method_name|
|
768
|
+
begin
|
769
|
+
send(method_name)
|
770
|
+
rescue => e
|
771
|
+
$stderr.puts("Global pre-hook '#{hook_name}' failed with: '#{e.message}'")
|
772
|
+
exit(1)
|
773
|
+
end
|
774
|
+
end
|
775
|
+
end
|
776
|
+
|
750
777
|
# Below are some basic command hooks that do the right thing
|
751
778
|
# when a service is configured as external via [package][service
|
752
779
|
|
data/lib/omnibus-ctl/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.0
|
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: 2018-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -66,7 +66,8 @@ files:
|
|
66
66
|
- lib/omnibus-ctl.rb
|
67
67
|
- lib/omnibus-ctl/version.rb
|
68
68
|
homepage: http://github.com/chef/omnibus-ctl
|
69
|
-
licenses:
|
69
|
+
licenses:
|
70
|
+
- Apache-2.0
|
70
71
|
metadata: {}
|
71
72
|
post_install_message:
|
72
73
|
rdoc_options: []
|
@@ -84,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
85
|
version: '0'
|
85
86
|
requirements: []
|
86
87
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.
|
88
|
+
rubygems_version: 2.6.13
|
88
89
|
signing_key:
|
89
90
|
specification_version: 4
|
90
91
|
summary: Provides command line control for omnibus packages
|