Class: Serverspec::Commands::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/serverspec/commands/base.rb

Direct Known Subclasses

Debian, Gentoo, RedHat, Solaris

Defined Under Namespace

Classes: NotImplementedError

Instance Method Summary collapse

Instance Method Details

#check_cron_entry(user, entry) ⇒ Object



58
59
60
61
# File 'lib/serverspec/commands/base.rb', line 58

def check_cron_entry user, entry
  entry_escaped = entry.gsub(/\*/, '\\*')
  "crontab -u #{user} -l | grep '#{entry_escaped}'"
end

#check_directory(directory) ⇒ Object



14
15
16
# File 'lib/serverspec/commands/base.rb', line 14

def check_directory directory
  "test -d #{directory}"
end

#check_enabled(service) ⇒ Object



6
7
8
# File 'lib/serverspec/commands/base.rb', line 6

def check_enabled service
  raise NotImplementedError.new
end

#check_file(file) ⇒ Object



10
11
12
# File 'lib/serverspec/commands/base.rb', line 10

def check_file file
  "test -f #{file}"
end

#check_file_contain(file, expected_pattern) ⇒ Object



42
43
44
# File 'lib/serverspec/commands/base.rb', line 42

def check_file_contain file, expected_pattern
  "grep -q '#{expected_pattern}' #{file} "
end

#check_group(group) ⇒ Object



22
23
24
# File 'lib/serverspec/commands/base.rb', line 22

def check_group group
  "getent group | grep -wq #{group}"
end

#check_grouped(file, group) ⇒ Object



54
55
56
# File 'lib/serverspec/commands/base.rb', line 54

def check_grouped file, group
  "stat -c %G #{file} | grep #{group}"
end

#check_installed(package) ⇒ Object



26
27
28
# File 'lib/serverspec/commands/base.rb', line 26

def check_installed package
  raise NotImplementedError.new
end


63
64
65
# File 'lib/serverspec/commands/base.rb', line 63

def check_link link, target
  "stat -c %N #{link} | grep #{target}"
end

#check_listening(port) ⇒ Object



30
31
32
# File 'lib/serverspec/commands/base.rb', line 30

def check_listening port
  "netstat -tunl | grep ':#{port} '"
end

#check_mode(file, mode) ⇒ Object



46
47
48
# File 'lib/serverspec/commands/base.rb', line 46

def check_mode file, mode
  "stat -c %a #{file} | grep #{mode}"
end

#check_owner(file, owner) ⇒ Object



50
51
52
# File 'lib/serverspec/commands/base.rb', line 50

def check_owner file, owner
  "stat -c %U #{file} | grep #{owner}"
end

#check_process(process) ⇒ Object



38
39
40
# File 'lib/serverspec/commands/base.rb', line 38

def check_process process
  "ps -e | grep -qw #{process}"
end

#check_running(service) ⇒ Object



34
35
36
# File 'lib/serverspec/commands/base.rb', line 34

def check_running service
  "service #{service} status"
end

#check_user(user) ⇒ Object



18
19
20
# File 'lib/serverspec/commands/base.rb', line 18

def check_user user
  "id #{user}"
end