Module: Machines::Commands::Checks
- Included in:
- Machines::Core
- Defined in:
- lib/machines/commands/checks.rb
Overview
The Checks
module is used to execute a command to check whether the
previous command was successful. These methods are useful when writing
your own custom commands.
Instance Method Summary collapse
- #check_command(command, match = nil) ⇒ Object
- #check_daemon(daemon, exists = true) ⇒ Object
- #check_dir(dir, exists = true) ⇒ Object
- #check_file(file, exists = true) ⇒ Object
- #check_gem(gem, version = nil) ⇒ Object
- #check_init_d(name) ⇒ Object
- #check_link(link) ⇒ Object
- #check_owner(user, path) ⇒ Object
- #check_package(package, exists = true) ⇒ Object
- #check_perms(perms, path) ⇒ Object
- #check_string(string, file) ⇒ Object
- #echo_result ⇒ Object
Instance Method Details
#check_command(command, match = nil) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/machines/commands/checks.rb', line 58 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
46 47 48 49 50 51 52 |
# File 'lib/machines/commands/checks.rb', line 46 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
28 29 30 |
# File 'lib/machines/commands/checks.rb', line 28 def check_dir dir, exists = true "test #{exists ? '' : '! '}-d #{dir} #{echo_result}" end |
#check_file(file, exists = true) ⇒ Object
20 21 22 |
# File 'lib/machines/commands/checks.rb', line 20 def check_file file, exists = true "test #{exists ? '' : '! '}-s #{file} #{echo_result}" end |
#check_gem(gem, version = nil) ⇒ Object
15 16 17 18 |
# File 'lib/machines/commands/checks.rb', line 15 def check_gem gem, version = nil version = " -v #{version}" if version "gem search #{gem}#{version} --installed #{echo_result}" end |
#check_init_d(name) ⇒ Object
54 55 56 |
# File 'lib/machines/commands/checks.rb', line 54 def check_init_d name "test -L /etc/rc0.d/K20#{name} #{echo_result}" end |
#check_link(link) ⇒ Object
24 25 26 |
# File 'lib/machines/commands/checks.rb', line 24 def check_link link "test -L #{link} #{echo_result}" end |
#check_owner(user, path) ⇒ Object
38 39 40 |
# File 'lib/machines/commands/checks.rb', line 38 def check_owner user, path "ls -la #{path} | grep \"#{user}.*#{user}\" #{echo_result}" end |
#check_package(package, exists = true) ⇒ Object
11 12 13 |
# File 'lib/machines/commands/checks.rb', line 11 def check_package package, exists = true "dpkg --get-selections | grep #{package}.*#{exists ? '' : 'de'}install #{echo_result}" end |
#check_perms(perms, path) ⇒ Object
32 33 34 35 36 |
# File 'lib/machines/commands/checks.rb', line 32 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
42 43 44 |
# File 'lib/machines/commands/checks.rb', line 42 def check_string string, file "grep \"#{string}\" #{file} #{echo_result}" end |
#echo_result ⇒ Object
7 8 9 |
# File 'lib/machines/commands/checks.rb', line 7 def echo_result '&& echo CHECK PASSED || echo CHECK FAILED' end |