CDSERVER_ROOT="//docbox/DBServer"
CDSERVER_PID = "//tmp"
CDSERVER_LOG= "#{CDSERVER_ROOT}/log"
NGINX_ROOT="/usr/local/nginx/sbin" #config in /usr/local/nginx/conf/nginx.conf
THIN_ROOT="/usr/local/bin/thin"
THIN_CONFIG=File.join(CDSERVER_ROOT,"thin_nginx.yml")

God.watch do |w|
  w.name          = "sphinx"
  w.group         ='docbox'
  w.start_grace   = 10.seconds
  w.restart_grace = 10.seconds
  w.interval      = 60.seconds
  w.dir           = CDSERVER_ROOT
  w.env 	  = {'RAILS_ENV' => "production" }
  w.start         = "rake ts:start"
  w.stop          = "rake ts:stop"
  w.restart       = "rake ts:restart"
  w.pid_file      = "//tmp/sphinx.pid"
  w.keepalive
end

God.watch do |w|
  w.name          = 'sidekiq'
  w.group         = 'docbox'
  w.start_grace   = 10.seconds
  w.restart_grace = 10.seconds
  w.stop_grace    = 10.seconds
  w.interval      = 60.seconds
  w.dir           = CDSERVER_ROOT
  w.start         = "bundle exec sidekiq -e production -c 3 -P #{CDSERVER_PID}/sidekiq.pid"
  w.stop          = "bundle exec sidekiqctl stop #{CDSERVER_PID}/sidekiq.pid 5"
  w.keepalive
  w.log           = File.join(CDSERVER_LOG, 'sidekiq.log')
  w.behavior(:clean_pid_file)
#  w.env           = {'HOME' => '/root'} ## for gpg
end

God.watch do |w|
  w.name          = 'clockwork'
  w.group         = 'docbox'
  w.start_grace   = 10.seconds
  w.restart_grace = 10.seconds
  w.stop_grace    = 10.seconds
  w.interval      = 60.seconds
  w.dir           = CDSERVER_ROOT

  w.start         = "bundle exec clockwork ./services/cdserver_maintenance_job.rb & echo $! > #{CDSERVER_PID}/clockwork.pid"
  w.stop          = "kill -QUIT `cat #{CDSERVER_PID}/clockwork.pid`"
  w.keepalive
  w.log           = File.join(CDSERVER_LOG, 'clockwork.log')
  w.behavior(:clean_pid_file)
  w.env           = {'RAILS_ENV' => "production" }
  w.pid_file      = "#{CDSERVER_PID}/clockwork.pid"
end

God.watch do |w|
  w.name          = "thin"
  w.group         ='docbox'
  w.dir           = CDSERVER_ROOT
  w.start_grace   = 10.seconds
  w.restart_grace = 10.seconds
  w.interval      = 60.seconds
  w.start         = "thin start --config ./thin_nginx.yml --log #{CDSERVER_LOG}/thin.log --pid //tmp/thin.pid"
  w.stop          = "thin stop --pid //tmp/thin.pid"
  w.restart       = "thin restart"
  w.pid_file      = "//tmp/thin.pid"
  w.log           = "#{CDSERVER_LOG}/thin.log"
  w.keepalive
end

#fayae - privat pub gem from ryan
God.watch do |w|
  w.name          = "private_pub"
  w.group         ='docbox'
  w.dir           = CDSERVER_ROOT
  w.start_grace   = 10.seconds
  w.restart_grace = 10.seconds
  w.interval      = 60.seconds
  w.env           = {'RAILS_ENV' => "production" }
  w.start         = "rackup private_pub.ru -s thin -E production -P #{CDSERVER_PID}/private_pub.pid"

  w.log           = File.join(CDSERVER_LOG, 'private_pub.log')
  w.pid_file      = "#{CDSERVER_PID}/private_pub.pid"
#   w.stop_signal = 'KILL'
  w.keepalive
end

#avahi daemon to register the converter and scanner
God.watch do |w|
  w.name 	  = "avahi"  
  w.group         ='docbox'
  w.dir           = CDSERVER_ROOT  
  w.start 	  = "bundle exec ruby #{CDSERVER_ROOT}/services/avahi_service_start_port.rb -p 8082 -e production"
  w.log           = "#{CDSERVER_LOG}/avahi.log"  
  w.keepalive
end

