+2018-08-25 Daigo Moriwaki <daigo at debian dot org>
+
+ * [shogi-server] Support a graceful shutdown.
+ A file named "STOP" in the base directory prevents the server from
+ starting new games including Floodgate matches.
+ (Closes #38544)
+
2018-04-07 Daigo Moriwaki <daigo at debian dot org>
* [shogi-server] Give more penalty on assigning matches with same
floodgate-0-240.conf.sample or shogi_server/league/floodgate.rb
for format details.
+GRACEFUL SHUTDOWN
+
+ A file named "STOP" in the base directory prevents the server from
+ starting new games including Floodgate matches.
+ When you want to stop the server gracefully, first, create a STOP file
+
+ $ touch STOP
+
+ then wait for a while until all the running games complete.
+ Now you can stop the process with no game interruptted by the 'kill'
+ command.
+
+ Note that when a server gets started, a STOP file, if any, will be
+ deleted automatically.
+
FLOODGATE SCHEDULE CONFIGURATIONS
You need to set starting times of floodgate groups in
$stderr.puts("server started as a deamon [Revision: #{ShogiServer::Revision}]") if $options["daemon"]
log_message("server started [Revision: #{ShogiServer::Revision}]")
+ if ShogiServer::STOP_FILE.exist?
+ log_message("Deleted the STOP file")
+ ShogiServer::STOP_FILE.delete
+ end
+
server.start do |client|
begin
# client.sync = true # this is already set in WEBrick
require 'webrick'
require 'fileutils'
require 'logger'
+require 'pathname'
require 'shogi_server/compatible'
require 'shogi_server/board'
"shogi_server/league/persistent.rb",
"shogi_server/pairing.rb"]
BASE_DIR = File.expand_path(File.dirname(__FILE__))
+STOP_FILE = Pathname.new(BASE_DIR).join("STOP")
def reload
RELOAD_FILES.each do |f|
end
module_function :reload
+##
+# When the STOP file exists, starting a new game is not allowed.
+def available?
+ return !STOP_FILE.exist?
+end
+module_function :available?
+
class Logger < ::Logger
def initialize(logdev, shift_age = 0, shift_size = 1048576)
end
def call
- if (! Login::good_game_name?(@game_name))
+ if (!ShogiServer::available?)
+ @player.write_safe("##[ERROR] As the service is going to shutdown shortly, starting new games is not allowed now.\n")
+ return :continue
+ elsif (! Login::good_game_name?(@game_name))
@player.write_safe(sprintf("##[ERROR] bad game name: %s.\n", @game_name))
if (/^(.+)-\d+-\d+F?$/ =~ @game_name)
if Login::good_identifier?($1)
next_instances = leagues.collect do |fg|
unless (fg.next_time - Time.now) > 0
- start_games(fg)
+ if ShogiServer::available?
+ start_games(fg)
+ else
+ log_message("The STOP file prevents from starting new Floodgate matches")
+ end
fg.charge # updates next_time
end
fg