Class: Serverspec::Commands::Solaris
- Inherits:
-
Base
- Object
- Base
- Serverspec::Commands::Solaris
show all
- Defined in:
- lib/serverspec/commands/solaris.rb
Instance Method Summary
collapse
-
#check_access_by_user(file, user, access) ⇒ Object
-
#check_belonging_group(user, group) ⇒ Object
-
#check_cron_entry(user, entry) ⇒ Object
-
#check_enabled(service) ⇒ Object
-
#check_file_contain_within(file, expected_pattern, from = nil, to = nil) ⇒ Object
-
#check_gid(group, gid) ⇒ Object
-
#check_home_directory(user, path_to_home) ⇒ Object
-
#check_installed(package) ⇒ Object
-
#check_ipfilter_rule(rule) ⇒ Object
-
#check_ipnat_rule(rule) ⇒ Object
-
#check_listening(port) ⇒ Object
-
#check_login_shell(user, path_to_shell) ⇒ Object
-
#check_running(service) ⇒ Object
-
#check_svcprop(svc, property, value) ⇒ Object
-
#check_svcprops(svc, property) ⇒ Object
-
#check_zfs(zfs, property = nil) ⇒ Object
Methods inherited from Base
#check_authorized_key, #check_directory, #check_file, #check_file_contain, #check_file_md5checksum, #check_group, #check_grouped, #check_installed_by_gem, #check_iptables_rule, #check_link, #check_mode, #check_mounted, #check_owner, #check_process, #check_reachable, #check_resolvable, #check_running_under_supervisor, #check_selinux, #check_uid, #check_user, #escape, #get_mode
Instance Method Details
#check_access_by_user(file, user, access) ⇒ Object
86
87
88
89
90
91
|
# File 'lib/serverspec/commands/solaris.rb', line 86
def check_access_by_user file, user, access
"su #{user} -c \"/usr/bin/test -#{access} #{file}\""
end
|
#check_belonging_group(user, group) ⇒ Object
69
70
71
|
# File 'lib/serverspec/commands/solaris.rb', line 69
def check_belonging_group user, group
"id -Gn #{escape(user)} | grep -- #{escape(group)}"
end
|
#check_cron_entry(user, entry) ⇒ Object
21
22
23
24
|
# File 'lib/serverspec/commands/solaris.rb', line 21
def check_cron_entry user, entry
entry_escaped = entry.gsub(/\*/, '\\*')
"crontab -l #{escape(user)} | grep -- #{escape(entry_escaped)}"
end
|
#check_enabled(service) ⇒ Object
4
5
6
|
# File 'lib/serverspec/commands/solaris.rb', line 4
def check_enabled service
"svcs -l #{escape(service)} 2> /dev/null | grep 'enabled true'"
end
|
#check_file_contain_within(file, expected_pattern, from = nil, to = nil) ⇒ Object
62
63
64
65
66
67
|
# File 'lib/serverspec/commands/solaris.rb', line 62
def check_file_contain_within file, expected_pattern, from=nil, to=nil
from ||= '1'
to ||= '$'
checker = check_file_contain("/dev/stdin", expected_pattern)
"sed -n #{escape(from)},#{escape(to)}p #{escape(file)} | #{checker}"
end
|
#check_gid(group, gid) ⇒ Object
73
74
75
76
|
# File 'lib/serverspec/commands/solaris.rb', line 73
def check_gid group, gid
regexp = "^#{group}:"
"getent group | grep -- #{escape(regexp)} | cut -f 3 -d ':' | grep -w -- #{escape(gid)}"
end
|
#check_home_directory(user, path_to_home) ⇒ Object
78
79
80
|
# File 'lib/serverspec/commands/solaris.rb', line 78
def check_home_directory user, path_to_home
"getent passwd #{escape(user)} | cut -f 6 -d ':' | grep -w -- #{escape(path_to_home)}"
end
|
#check_installed(package) ⇒ Object
8
9
10
|
# File 'lib/serverspec/commands/solaris.rb', line 8
def check_installed package
"pkg list -H #{escape(package)} 2> /dev/null"
end
|
#check_ipfilter_rule(rule) ⇒ Object
39
40
41
|
# File 'lib/serverspec/commands/solaris.rb', line 39
def check_ipfilter_rule rule
"/sbin/ipfstat -io 2> /dev/null | grep -- #{escape(rule)}"
end
|
#check_ipnat_rule(rule) ⇒ Object
43
44
45
46
|
# File 'lib/serverspec/commands/solaris.rb', line 43
def check_ipnat_rule rule
regexp = "^#{rule}$"
"/sbin/ipnat -l 2> /dev/null | grep -- #{escape(regexp)}"
end
|
#check_listening(port) ⇒ Object
12
13
14
15
|
# File 'lib/serverspec/commands/solaris.rb', line 12
def check_listening port
regexp = "\.#{port} "
"netstat -an 2> /dev/null | egrep 'LISTEN|Idle' | grep -- #{escape(regexp)}"
end
|
#check_login_shell(user, path_to_shell) ⇒ Object
82
83
84
|
# File 'lib/serverspec/commands/solaris.rb', line 82
def check_login_shell user, path_to_shell
"getent passwd #{escape(user)} | cut -f 7 -d ':' | grep -w -- #{escape(path_to_shell)}"
end
|
#check_running(service) ⇒ Object
17
18
19
|
# File 'lib/serverspec/commands/solaris.rb', line 17
def check_running service
"svcs -l #{escape(service)} status 2> /dev/null |grep 'state online'"
end
|
#check_svcprop(svc, property, value) ⇒ Object
48
49
50
51
|
# File 'lib/serverspec/commands/solaris.rb', line 48
def check_svcprop svc, property, value
regexp = "^#{value}$"
"svcprop -p #{escape(property)} #{escape(svc)} | grep -- #{escape(regexp)}"
end
|
#check_svcprops(svc, property) ⇒ Object
53
54
55
56
57
58
59
60
|
# File 'lib/serverspec/commands/solaris.rb', line 53
def check_svcprops svc, property
commands = []
property.sort.each do |key, value|
regexp = "^#{value}$"
commands << "svcprop -p #{escape(key)} #{escape(svc)} | grep -- #{escape(regexp)}"
end
commands.join(' && ')
end
|
#check_zfs(zfs, property = nil) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/serverspec/commands/solaris.rb', line 26
def check_zfs zfs, property=nil
if property.nil?
"/sbin/zfs list -H #{escape(zfs)}"
else
commands = []
property.sort.each do |key, value|
regexp = "^#{value}$"
commands << "/sbin/zfs list -H -o #{escape(key)} #{escape(zfs)} | grep -- #{escape(regexp)}"
end
commands.join(' && ')
end
end
|