1

I am using guard to watch a directory, as soon as files are uploaded into the directory Guard a rake process gets triggered.

Is there any way to run Guard as a daemon process, Not been able to find out anywhere in the documentation.

mohit
  • 1,913
  • 3
  • 16
  • 23

3 Answers3

4

Guard does not have a built in option to run as daemon, but you could use nohup and ampersand to run it in the background:

nohup guard &

Running in the background should not print anything to the console, so I'd redirect the streams:

nohup guard >/dev/null 2>&1 &

In that case I'd recommend to deactivate the interactor and use file logging in your Guardfile:

interactor :off
logger device: 'guard.log'
Netzpirat
  • 5,481
  • 1
  • 22
  • 21
2

If I understand your question correctly, i.e. run guard as a daemon, you can supply the daemon option to guard as:

guard 'rails', daemon: true do
  watch(...)
  ...
end

Reference other guard options.

vee
  • 38,255
  • 7
  • 74
  • 78
  • Thanks for your valuable input, but i assume the reference you have provide is for guard-rails. I wanted guard itself to run as a daemon process. The guard gem. – mohit Jan 02 '14 at 09:41
  • BTW, you posted your question with a "ruby on rails" tag, and actually most people use guard-rails (like me), so this answer was actually more relevant for me – Dorian Oct 14 '14 at 17:06
0

You should have a look to the documentation to start guard programmatically on Rails ;)

In short, create an initializer for Guard containing:

require 'guard'
require 'guard/commander' # needed because of https://github.com/guard/guard/issues/793

# Start Guard only with rails.
if File.basename($0, '.*') == 'rails'
  fork do
    if __FILE__ == '(irb)'
    end

    Guard.guards 'sass'
    Guard.start :no_interactions => true
  end
end
Pirhoo
  • 680
  • 8
  • 21