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.
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.
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'
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.
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