From: Daigo Moriwaki Date: Sat, 25 Aug 2018 09:41:38 +0000 (+0900) Subject: * [shogi-server] Support a graceful shutdown. (Closes #38544) X-Git-Url: http://git.osdn.net/view?p=shogi-server%2Fshogi-server.git;a=commitdiff_plain;h=a29f0d5a40176fd026f13004fa4a519e4e934e86 * [shogi-server] Support a graceful shutdown. (Closes #38544) A file named "STOP" in the base directory prevents the server from starting new games including Floodgate matches. --- diff --git a/changelog b/changelog index 707b575..b3df157 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,10 @@ +2018-08-25 Daigo Moriwaki + + * [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 * [shogi-server] Give more penalty on assigning matches with same diff --git a/shogi-server b/shogi-server index 530dbb1..21bc9d1 100755 --- a/shogi-server +++ b/shogi-server @@ -123,6 +123,21 @@ EXAMPLES 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 @@ -458,6 +473,11 @@ def main $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 diff --git a/shogi_server.rb b/shogi_server.rb index 69dae89..6a8c21f 100644 --- a/shogi_server.rb +++ b/shogi_server.rb @@ -28,6 +28,7 @@ require 'digest/md5' require 'webrick' require 'fileutils' require 'logger' +require 'pathname' require 'shogi_server/compatible' require 'shogi_server/board' @@ -58,6 +59,7 @@ RELOAD_FILES = ["shogi_server/league/floodgate.rb", "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| @@ -66,6 +68,13 @@ def reload 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) diff --git a/shogi_server/command.rb b/shogi_server/command.rb index dedbaae..ad8684d 100644 --- a/shogi_server/command.rb +++ b/shogi_server/command.rb @@ -497,7 +497,10 @@ module ShogiServer 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) diff --git a/shogi_server/league/floodgate_thread.rb b/shogi_server/league/floodgate_thread.rb index 0c1759b..a665704 100644 --- a/shogi_server/league/floodgate_thread.rb +++ b/shogi_server/league/floodgate_thread.rb @@ -103,7 +103,11 @@ module ShogiServer 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