daemonize.rb 691 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env ruby
  2. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  3. require 'daemons'
  4. #
  5. # Generic daemonization script for legacy CI tests.
  6. #
  7. def exit_with_usage
  8. puts 'Usage: daemonize.rb start|stop -- $name_of_pidfile $commandline'
  9. exit false
  10. end
  11. dir = File.expand_path(File.join(__dir__, '../..'))
  12. daemon_options = {
  13. multiple: false,
  14. dir_mode: :normal,
  15. dir: File.join(dir, 'tmp', 'pids'),
  16. backtrace: true
  17. }
  18. separator_index = ARGV.index('--')
  19. exit_with_usage if separator_index.nil?
  20. args = ARGV[(separator_index + 1)..]
  21. exit_with_usage if args.count < 2
  22. Daemons.run_proc(args[0], daemon_options) do
  23. Dir.chdir dir
  24. exec(args[1])
  25. end