sos 0.2.6 → 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/lib/sos.rb +18 -12
- data/lib/sos/services.rb +34 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 349b29c2085bb1ccd9feac783a9ecfec2d97f536
|
4
|
+
data.tar.gz: 0bfe909da1aced6c8aaaabe44dd0c6b25174c06f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fc7f026f206af038dbd723bf9bf1bd877beed488374f552d2e4228f6fafe82aedc4507f4e512e7653284011cc66305d008bb8c00a52062cfe5663df30ad369a
|
7
|
+
data.tar.gz: 5503c0556fa1a0dc22a3a2e489212211c30161295a6b3f91d8a9770f26ff26e9d59a6cf002fc811fca8d5d67e9726346fae5e8786196b6eea11fd4a36cf90ab7
|
data/lib/sos.rb
CHANGED
@@ -21,18 +21,22 @@ SYNTAX =
|
|
21
21
|
sos help
|
22
22
|
|
23
23
|
Options:
|
24
|
-
-r, --runlevel <RUNLEVEL>
|
25
|
-
|
24
|
+
-r, --runlevel <RUNLEVEL>
|
25
|
+
Change run-level. Default is level 3.
|
26
|
+
-s, --selector <NAME>, ... ,<NAME>
|
27
|
+
Assign selector. Default is "openstack,neutron".
|
28
|
+
-h, --help
|
29
|
+
This help
|
26
30
|
|
27
31
|
Commands:
|
28
32
|
list List available OpenStack services
|
29
33
|
logs Runs "tail -f"
|
30
|
-
restart Runs "service restart"
|
31
|
-
start Runs "service start"
|
32
|
-
status Runs "service status"
|
33
|
-
stop Runs "service stop"
|
34
|
+
restart Runs "service restart" on enabled services
|
35
|
+
start Runs "service start" on enabled services
|
36
|
+
status Runs "service status" on enabled services
|
37
|
+
stop Runs "service stop" on enabled services
|
34
38
|
|
35
|
-
<SERVICE>
|
39
|
+
<SERVICE> Service name
|
36
40
|
}
|
37
41
|
|
38
42
|
class Syntax
|
@@ -40,7 +44,7 @@ class Syntax
|
|
40
44
|
@command = nil
|
41
45
|
@options = {
|
42
46
|
:runlevel => 3,
|
43
|
-
:selector
|
47
|
+
:selector => 'openstack,neutron',
|
44
48
|
:all => false }
|
45
49
|
@arguments = []
|
46
50
|
|
@@ -50,7 +54,7 @@ class Syntax
|
|
50
54
|
@options[:all] = true
|
51
55
|
when '-s', '--selector'
|
52
56
|
line.shift
|
53
|
-
@options[:selector] = line[0]
|
57
|
+
@options[:selector] = line[0].gsub(/\s*/,'')
|
54
58
|
when '-r', '--run_level'
|
55
59
|
line.shift
|
56
60
|
@options[:runlevel] = line[0].to_i
|
@@ -68,7 +72,9 @@ class Syntax
|
|
68
72
|
end
|
69
73
|
|
70
74
|
def run
|
71
|
-
|
75
|
+
|
76
|
+
services_list = Services.build_list(@options[:selector], @options[:runlevel], @arguments)
|
77
|
+
services = Services.new(services_list, OpenStack::LOGS)
|
72
78
|
|
73
79
|
case @command
|
74
80
|
when /status/i, /start/i, /stop/i, /restart/i
|
@@ -82,8 +88,8 @@ class Syntax
|
|
82
88
|
}
|
83
89
|
exec("tail -f #{logs}") if logs
|
84
90
|
when /list/i
|
85
|
-
services.
|
86
|
-
puts service
|
91
|
+
services.by_name.each { |service|
|
92
|
+
puts service
|
87
93
|
}
|
88
94
|
when 'test'
|
89
95
|
p self
|
data/lib/sos/services.rb
CHANGED
@@ -2,9 +2,9 @@ class Service
|
|
2
2
|
attr_reader :name, :state, :logs
|
3
3
|
|
4
4
|
def initialize(name, state, logs)
|
5
|
-
@name
|
6
|
-
@state = state =~ /on/i ? true : false
|
7
|
-
@logs
|
5
|
+
@name = name
|
6
|
+
@state = state =~ /on|enabled/i ? true : false
|
7
|
+
@logs = logs
|
8
8
|
end
|
9
9
|
|
10
10
|
def has?(filter)
|
@@ -12,40 +12,55 @@ class Service
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def to_s
|
15
|
-
@
|
15
|
+
state = @state ? 'enabled' : 'disabled'
|
16
|
+
@name + ':' + state
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
20
|
class Services
|
20
|
-
def
|
21
|
-
|
21
|
+
def self.build_list(selectors, run_level, filters)
|
22
|
+
# Returns each service on a line with
|
23
|
+
# name:state
|
24
|
+
|
25
|
+
selector = selectors.split(',').join('|')
|
22
26
|
|
23
|
-
list
|
27
|
+
list=''
|
28
|
+
redhat = %x{cat /etc/redhat-release}
|
29
|
+
case redhat
|
30
|
+
when /Red Hat Enterprise Linux/
|
31
|
+
if redhat =~ /release 6/
|
32
|
+
list = %x{ chkconfig --list | awk '/#{selector}/ {print $1":"$#{run_level+2}}'}
|
33
|
+
list.gsub!(/:\d:/,':')
|
34
|
+
end
|
35
|
+
when /Fedora/
|
36
|
+
list = %x{ systemctl list-unit-files | awk '/#{selector}/ {print}'}
|
37
|
+
list.gsub!(/\.service[\s]*/,':')
|
38
|
+
end
|
24
39
|
|
25
40
|
if filters != []
|
26
41
|
filtered = ''
|
27
|
-
list.
|
42
|
+
list.each_line { |line|
|
28
43
|
filters.each { |filter| filtered << line if line =~ /#{filter}/ }
|
29
44
|
}
|
30
45
|
list = filtered
|
31
46
|
end
|
47
|
+
list
|
48
|
+
end
|
32
49
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
state =
|
37
|
-
log =
|
50
|
+
def initialize(service_list, services_logs)
|
51
|
+
@services = []
|
52
|
+
service_list.each_line { |line|
|
53
|
+
name, state = line.chop.split(':')
|
54
|
+
log = services_logs[name] ? services_logs[name] : ''
|
38
55
|
@services << Service.new(name, state, log)
|
39
56
|
}
|
57
|
+
@services
|
40
58
|
end
|
41
59
|
|
42
|
-
def
|
43
|
-
return @services
|
60
|
+
def by_name
|
44
61
|
list = []
|
45
|
-
|
46
|
-
|
47
|
-
list << service if @service.has?(filter)
|
48
|
-
}
|
62
|
+
@services.each { |service|
|
63
|
+
list << service
|
49
64
|
}
|
50
65
|
list
|
51
66
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilles Dubreuil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Easy manipulation of OpenStack services and view corresponding log files
|
14
14
|
for a specific host. Allows grouping part or all services at once.
|