Module: Appserver::Utils
- Defined in:
- lib/appserver/utils.rb
Class Method Summary collapse
- .find_in_path(name) ⇒ Object
- .number_of_cpus ⇒ Object
- .safe_replace_file(filename) {|tempfile| ... } ⇒ Object
- .system_domainname ⇒ Object
- .system_hostname ⇒ Object
Class Method Details
.find_in_path(name) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/appserver/utils.rb', line 8 def find_in_path (name) ENV['PATH'].split(':').each do |path| fn = File.join(path, name) return fn if File.executable?(fn) end nil end |
.number_of_cpus ⇒ Object
24 25 26 27 28 |
# File 'lib/appserver/utils.rb', line 24 def number_of_cpus if File.exist?('/proc/cpuinfo') File.readlines('/proc/cpuinfo').grep(/^processor\s+:\s+\d+/).size end end |
.safe_replace_file(filename) {|tempfile| ... } ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/appserver/utils.rb', line 30 def safe_replace_file (filename) tempfile = Tempfile.new(File.basename(filename) + '.', File.dirname(filename)) if File.exist?(filename) tempfile.chown(File.stat(filename).uid, File.stat(filename).gid) tempfile.chmod(File.stat(filename).mode) end yield tempfile tempfile.close File.unlink(filename) if File.exist?(filename) File.rename(tempfile.path, filename) end |
.system_domainname ⇒ Object
20 21 22 |
# File 'lib/appserver/utils.rb', line 20 def system_domainname system_hostname.sub(/^[^.]+\./, '') end |
.system_hostname ⇒ Object
16 17 18 |
# File 'lib/appserver/utils.rb', line 16 def system_hostname Socket.gethostname end |