2018-08-07 15:13:20 +08:00
|
|
|
#!/usr/bin/env ruby
|
2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
2018-08-07 15:13:20 +08:00
|
|
|
|
|
|
|
require 'pathname'
|
|
|
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
|
|
|
Pathname.new(__FILE__).realpath)
|
|
|
|
|
|
|
|
require 'rubygems'
|
|
|
|
require 'bundler/setup'
|
|
|
|
|
2019-09-11 15:35:58 +08:00
|
|
|
dev_mode = false
|
|
|
|
|
2018-08-07 15:13:20 +08:00
|
|
|
# in development do some fussing around, to automate config
|
|
|
|
if !ARGV.include?("-E") &&
|
|
|
|
!ARGV.include?("--env") &&
|
|
|
|
(ENV["RAILS_ENV"] == "development" || !ENV["RAILS_ENV"])
|
|
|
|
|
2019-09-11 15:35:58 +08:00
|
|
|
dev_mode = true
|
|
|
|
|
2018-08-07 15:13:20 +08:00
|
|
|
ARGV.push("-N")
|
|
|
|
if !ARGV.include?("-c") && !ARGV.include?("--config-file")
|
|
|
|
ARGV.push("-c")
|
|
|
|
ARGV.push(File.expand_path("../../config/unicorn.conf.rb",
|
|
|
|
Pathname.new(__FILE__).realpath))
|
|
|
|
end
|
|
|
|
|
2018-08-15 08:35:24 +08:00
|
|
|
# we do not want to listen on 2 ports, so lets fix it
|
|
|
|
if (idx = ARGV.index("-p")) && (port = ARGV[idx + 1].to_i) > 0
|
|
|
|
ENV["UNICORN_PORT"] ||= port.to_s
|
|
|
|
end
|
|
|
|
|
2018-08-07 16:20:08 +08:00
|
|
|
ENV["UNICORN_PORT"] ||= "9292"
|
2018-08-17 08:01:44 +08:00
|
|
|
|
|
|
|
if ARGV.delete("-x")
|
|
|
|
puts "Running without sidekiq"
|
|
|
|
ENV["UNICORN_SIDEKIQS"] = "0"
|
|
|
|
end
|
|
|
|
|
2018-08-07 16:20:08 +08:00
|
|
|
ENV["UNICORN_SIDEKIQS"] ||= "1"
|
2018-08-07 16:27:44 +08:00
|
|
|
|
2018-08-07 15:13:20 +08:00
|
|
|
end
|
|
|
|
|
2018-08-17 08:01:44 +08:00
|
|
|
if ARGV.include?("--help")
|
|
|
|
fork do
|
|
|
|
load Gem.bin_path('unicorn', 'unicorn')
|
|
|
|
end
|
|
|
|
Process.wait
|
|
|
|
puts "Extra Discourse Options:"
|
|
|
|
puts " -x run without sidekiq"
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
2019-09-11 15:43:36 +08:00
|
|
|
# this dev_mode hackery enables, the following to be used to restart unicorn:
|
2019-09-11 15:35:58 +08:00
|
|
|
#
|
2019-09-11 15:43:36 +08:00
|
|
|
# pkill -USR2 -f 'ruby bin/unicorn'
|
2019-09-11 15:35:58 +08:00
|
|
|
#
|
|
|
|
# This is handy if you want to bind a key to restarting unicorn in dev
|
|
|
|
|
|
|
|
if dev_mode
|
|
|
|
restart = true
|
|
|
|
while restart
|
|
|
|
restart = false
|
|
|
|
pid = fork do
|
|
|
|
load Gem.bin_path('unicorn', 'unicorn')
|
|
|
|
end
|
|
|
|
done = false
|
|
|
|
|
|
|
|
Signal.trap('INT') do
|
|
|
|
# wait for parent to be done
|
|
|
|
end
|
|
|
|
|
|
|
|
Signal.trap('USR2') do
|
|
|
|
Process.kill('QUIT', pid)
|
|
|
|
puts "RESTARTING UNICORN"
|
|
|
|
restart = true
|
|
|
|
end
|
|
|
|
|
|
|
|
while !done
|
|
|
|
sleep 1
|
|
|
|
done = Process.waitpid(pid, Process::WNOHANG)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
load Gem.bin_path('unicorn', 'unicorn')
|
|
|
|
end
|