Guest User

Untitled

a guest
Apr 25th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. diff --git a/lib/god/process.rb b/lib/god/process.rb
  2. index 338da5e..6cbc867 100644
  3. --- a/lib/god/process.rb
  4. +++ b/lib/god/process.rb
  5. @@ -6,7 +6,7 @@ module God
  6. :unix_socket, :chroot, :env, :dir
  7.  
  8. def initialize
  9. - self.log = '/dev/null'
  10. + self.log = nil
  11.  
  12. @pid_file = nil
  13. @tracking_pid = true
  14. @@ -101,19 +101,19 @@ module God
  15. end
  16.  
  17. # log dir must exist
  18. - if !File.exist?(File.dirname(self.log))
  19. + if self.log && !File.exist?(File.dirname(self.log))
  20. valid = false
  21. applog(self, :error, "Log directory '#{File.dirname(self.log)}' does not exist")
  22. end
  23.  
  24. # log file or dir must be writable
  25. - if File.exist?(self.log)
  26. + if self.log && File.exist?(self.log)
  27. unless file_writable?(self.log)
  28. valid = false
  29. applog(self, :error, "Log file '#{self.log}' exists but is not writable by #{self.uid || Etc.getlogin}")
  30. end
  31. else
  32. - unless file_writable?(File.dirname(self.log))
  33. + if self.log && !file_writable?(File.dirname(self.log))
  34. valid = false
  35. applog(self, :error, "Log directory '#{File.dirname(self.log)}' is not writable by #{self.uid || Etc.getlogin}")
  36. end
  37. @@ -282,7 +282,14 @@ module God
  38. #
  39. # Returns nothing
  40. def spawn(command)
  41. + # If we aren't logging anything, let's save it to the app logger
  42. + if !self.log_cmd && !self.log
  43. + read_log_pipe, write_log_pipe = IO.pipe
  44. + end
  45. +
  46. fork do
  47. + read_log_pipe.close if read_log_pipe
  48. +
  49. uid_num = Etc.getpwnam(self.uid).uid if self.uid
  50. gid_num = Etc.getgrnam(self.gid).gid if self.gid
  51.  
  52. @@ -297,8 +304,10 @@ module God
  53. STDIN.reopen "/dev/null"
  54. if self.log_cmd
  55. STDOUT.reopen IO.popen(self.log_cmd, "a")
  56. - else
  57. + elsif self.log
  58. STDOUT.reopen file_in_chroot(self.log), "a"
  59. + else
  60. + STDOUT.reopen write_log_pipe
  61. end
  62. STDERR.reopen STDOUT
  63.  
  64. @@ -313,6 +322,18 @@ module God
  65.  
  66. exec command unless command.empty?
  67. end
  68. +
  69. + # If we aren't doing anything with logging, send the log data to the
  70. + # app logger
  71. + if !self.log_cmd && !self.log
  72. + write_log_pipe.close
  73. +
  74. + Thread.new(read_log_pipe) do |io|
  75. + io.each_line do |line|
  76. + applog(self, :info, "#{self.name}: #{line}")
  77. + end
  78. + end
  79. + end
  80. end
  81.  
  82. # Ensure that a stop command actually stops the process. Force kill
Add Comment
Please, Sign In to add comment