scheduler.rb 924 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. worker_count = 2
  14. (1..worker_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, worker_count)
  29. end
  30. }