Module: Machines::Checks

Defined in:
lib/machines/checks.rb

Instance Method Summary collapse

Instance Method Details

#check_command(command, match = nil) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/machines/checks.rb', line 54

def check_command command, match = nil
  if match
    "#{command} | grep #{match} #{echo_result}"
  else
    "#{command} #{echo_result}"
  end
end

#check_daemon(daemon, exists = true) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/machines/checks.rb', line 42

def check_daemon daemon, exists = true
  command = 'ps aux'
  search_for = "| grep #{daemon}"
  remove_grep = '| grep -v grep'
  negative = "| grep -v #{daemon} " unless exists
  "#{command} #{search_for} #{remove_grep} #{negative}#{echo_result}"
end

#check_dir(dir, exists = true) ⇒ Object



24
25
26
# File 'lib/machines/checks.rb', line 24

def check_dir dir, exists = true
  "test #{exists ? '' : '! '}-d #{dir} #{echo_result}"
end

#check_file(file, exists = true) ⇒ Object



16
17
18
# File 'lib/machines/checks.rb', line 16

def check_file file, exists = true
  "test #{exists ? '' : '! '}-s #{file} #{echo_result}"
end

#check_gem(gem, version = nil) ⇒ Object



11
12
13
14
# File 'lib/machines/checks.rb', line 11

def check_gem gem, version = nil
  version = " -v #{version}" if version
  "gem search #{gem}#{version} --installed #{echo_result}"
end

#check_init_d(name) ⇒ Object



50
51
52
# File 'lib/machines/checks.rb', line 50

def check_init_d name
  "test -L /etc/rc0.d/K20#{name} #{echo_result}"
end


20
21
22
# File 'lib/machines/checks.rb', line 20

def check_link link
  "test -L #{link} #{echo_result}"
end

#check_owner(user, path) ⇒ Object



34
35
36
# File 'lib/machines/checks.rb', line 34

def check_owner user, path
  "ls -la #{path} | grep \"#{user}.*#{user}\" #{echo_result}"
end

#check_package(package, exists = true) ⇒ Object



7
8
9
# File 'lib/machines/checks.rb', line 7

def check_package package, exists = true
  "dpkg --get-selections | grep #{package}.*#{exists ? '' : 'de'}install #{echo_result}"
end

#check_perms(perms, path) ⇒ Object



28
29
30
31
32
# File 'lib/machines/checks.rb', line 28

def check_perms perms, path
  perms = perms.to_s
  mods = %w(--- --x -w- -wx r-- r-x rw- rwx)
  "ls -la #{path} | grep #{mods[perms[0..0].to_i]}#{mods[perms[1..1].to_i]}#{mods[perms[2..2].to_i]} #{echo_result}"
end

#check_string(string, file) ⇒ Object



38
39
40
# File 'lib/machines/checks.rb', line 38

def check_string string, file
  "grep \"#{string}\" #{file} #{echo_result}"
end

#echo_resultObject



3
4
5
# File 'lib/machines/checks.rb', line 3

def echo_result
  '&& echo CHECK PASSED || echo CHECK FAILED'
end