scheduler.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env ruby
  2. # Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
  3. $LOAD_PATH << './lib'
  4. require 'rubygems'
  5. require 'daemons'
  6. dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
  7. daemon_options = {
  8. :multiple => true,
  9. :dir_mode => :normal,
  10. :dir => File.join(dir, 'tmp', 'pids'),
  11. :backtrace => true
  12. }
  13. runner_count = 2
  14. (1..runner_count).each {|count|
  15. name = 'scheduler_runner' + count.to_s
  16. Daemons.run_proc(name, daemon_options) do
  17. if ARGV.include?('--')
  18. ARGV.slice! 0..ARGV.index('--')
  19. else
  20. ARGV.clear
  21. end
  22. Dir.chdir dir
  23. RAILS_ENV = ARGV.first || ENV['RAILS_ENV'] || 'development'
  24. $stdout.reopen( dir + "/log/" + name + "_out.log", "w")
  25. $stderr.reopen( dir + "/log/" + name + "_err.log", "w")
  26. require File.join(dir, "config", "environment")
  27. require 'scheduler'
  28. Scheduler.run(count, runner_count)
  29. end
  30. }
  31. name = 'scheduler_worker'
  32. Daemons.run_proc(name, daemon_options) do
  33. if ARGV.include?('--')
  34. ARGV.slice! 0..ARGV.index('--')
  35. else
  36. ARGV.clear
  37. end
  38. Dir.chdir dir
  39. RAILS_ENV = ARGV.first || ENV['RAILS_ENV'] || 'development'
  40. $stdout.reopen( dir + "/log/" + name + "_out.log", "w")
  41. $stderr.reopen( dir + "/log/" + name + "_err.log", "w")
  42. require File.join(dir, "config", "environment")
  43. require 'scheduler'
  44. Scheduler.worker
  45. end