mirror of
https://github.com/discourse/discourse.git
synced 2024-12-03 03:43:40 +08:00
7c084c7cab
Well all this does is amends a commit comment cause I was over eager and pushed previous commit. This is the comment I wanted.... This allows `pkill -USR2 -f 'ruby bin/unicorn'` to restart current unicorn It is handy if you want to bind a keyboard shortcut for unicorn restarts in dev. By doing so you can avoid finding the terminal, hitting ctrl-c and then hitting up, enter, heading back to browser. It saves time. Automate stuff, you will not regret it...
86 lines
1.8 KiB
Ruby
Executable File
86 lines
1.8 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
# frozen_string_literal: true
|
|
|
|
require 'pathname'
|
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
|
Pathname.new(__FILE__).realpath)
|
|
|
|
require 'rubygems'
|
|
require 'bundler/setup'
|
|
|
|
dev_mode = false
|
|
|
|
# in development do some fussing around, to automate config
|
|
if !ARGV.include?("-E") &&
|
|
!ARGV.include?("--env") &&
|
|
(ENV["RAILS_ENV"] == "development" || !ENV["RAILS_ENV"])
|
|
|
|
dev_mode = true
|
|
|
|
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
|
|
|
|
# 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
|
|
|
|
ENV["UNICORN_PORT"] ||= "9292"
|
|
|
|
if ARGV.delete("-x")
|
|
puts "Running without sidekiq"
|
|
ENV["UNICORN_SIDEKIQS"] = "0"
|
|
end
|
|
|
|
ENV["UNICORN_SIDEKIQS"] ||= "1"
|
|
|
|
end
|
|
|
|
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
|
|
|
|
# this dev_mode hackery enables, the following to be used to restart unicorn:
|
|
#
|
|
# pkill -USR2 -f 'ruby bin/unicorn'
|
|
#
|
|
# 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
|