• R/O
  • HTTP
  • SSH
  • HTTPS

shogi-server: Commit

shogi-server source


Commit MetaInfo

Revisionfe5c0f11e674eab8788853c265d4bd447bc7efb9 (tree)
Time2018-08-26 09:19:02
AuthorDaigo Moriwaki <daigo@debi...>
CommiterDaigo Moriwaki

Log Message

Merge remote-tracking branch 'origin/master' into wdoor-stable

Change Summary

Incremental Difference

--- a/Dockerfile
+++ b/Dockerfile
@@ -18,4 +18,4 @@ RUN gem install rgl
1818 COPY . ./
1919
2020 EXPOSE $PORT
21-CMD ./shogi-server --player-log-dir ./player-logs --max-identifier $MAX_IDENTIFIER $EVENT $PORT
21+CMD ./shogi-server --daemon /logs --max-identifier $MAX_IDENTIFIER $EVENT $PORT & tail -F /logs/shogi-server.log
--- a/Makefile
+++ b/Makefile
@@ -5,21 +5,21 @@ doc: clean
55 . shogi-server README mk_html mk_rate csa-file-filter
66
77 .PHONY: test-run
8-test-run:
8+test-run:
99 ./shogi-server --floodgate-games floodgate-600-10,floodgate-3600-0 hoge 4000
1010
1111
1212 .PHONY: test-run-daemon
13-test-run-daemon:
13+test-run-daemon:
1414 ./shogi-server --floodgate-games floodgate-600-10,floodgate-3600-0 --daemon . --pid-file ./shogi-server.pid --player-log-dir ./player-logs hoge 4000
1515
16-.PHONY: stop-daemn
16+.PHONY: stop-daemon
1717 stop-daemon:
1818 kill `cat shogi-server.pid`
1919
2020 .PHONY: test-time-run
21-test-time-run:
22- ruby -r sample/test_time.rb ./shogi-server --floodgate-games floodgate-900-0,floodgate-3600-0 hoge 4000
21+test-time-run:
22+ ruby -r sample/test_time.rb ./shogi-server --floodgate-games floodgate-900-0,floodgate-3600-0 hoge 4000
2323
2424 .PHONY: image-build
2525 image-build: .image-build
--- a/changelog
+++ b/changelog
@@ -1,3 +1,14 @@
1+2018-08-25 Daigo Moriwaki <daigo at debian dot org>
2+
3+ * [shogi-server] Support a graceful shutdown.
4+ A file named "STOP" in the base directory prevents the server from
5+ starting new games including Floodgate matches.
6+ (Closes #38544)
7+ * [shogi-server] Create a directory for a PID file.
8+ To put a PID file such as /var/run/shogi-server/shogi-server.pid, if
9+ directories do not exist, they will be created recursively.
10+ (Closes #38546)
11+
112 2018-04-07 Daigo Moriwaki <daigo at debian dot org>
213
314 * [shogi-server] Give more penalty on assigning matches with same
--- a/shogi-server
+++ b/shogi-server
@@ -34,6 +34,7 @@ require 'shogi_server'
3434 require 'shogi_server/config'
3535 require 'shogi_server/util'
3636 require 'shogi_server/league/floodgate_thread.rb'
37+require 'pathname'
3738 require 'tempfile'
3839
3940 #################################################
@@ -123,6 +124,21 @@ EXAMPLES
123124 floodgate-0-240.conf.sample or shogi_server/league/floodgate.rb
124125 for format details.
125126
127+GRACEFUL SHUTDOWN
128+
129+ A file named "STOP" in the base directory prevents the server from
130+ starting new games including Floodgate matches.
131+ When you want to stop the server gracefully, first, create a STOP file
132+
133+ $ touch STOP
134+
135+ then wait for a while until all the running games complete.
136+ Now you can stop the process with no game interruptted by the 'kill'
137+ command.
138+
139+ Note that when a server gets started, a STOP file, if any, will be
140+ deleted automatically.
141+
126142 FLOODGATE SCHEDULE CONFIGURATIONS
127143
128144 You need to set starting times of floodgate groups in
@@ -256,6 +272,8 @@ def check_command_line
256272
257273 if $options["pid-file"]
258274 $options["pid-file"] = File.expand_path($options["pid-file"], $topdir)
275+ path = Pathname.new($options["pid-file"])
276+ path.dirname().mkpath()
259277 unless ShogiServer::is_writable_file? $options["pid-file"]
260278 usage
261279 $stderr.puts "Can not create the pid file: %s" % [$options["pid-file"]]
@@ -458,6 +476,11 @@ def main
458476 $stderr.puts("server started as a deamon [Revision: #{ShogiServer::Revision}]") if $options["daemon"]
459477 log_message("server started [Revision: #{ShogiServer::Revision}]")
460478
479+ if ShogiServer::STOP_FILE.exist?
480+ log_message("Deleted the STOP file")
481+ ShogiServer::STOP_FILE.delete
482+ end
483+
461484 server.start do |client|
462485 begin
463486 # client.sync = true # this is already set in WEBrick
--- a/shogi_server.rb
+++ b/shogi_server.rb
@@ -28,6 +28,7 @@ require 'digest/md5'
2828 require 'webrick'
2929 require 'fileutils'
3030 require 'logger'
31+require 'pathname'
3132
3233 require 'shogi_server/compatible'
3334 require 'shogi_server/board'
@@ -52,12 +53,13 @@ Default_Max_Moves = 256
5253 Default_Least_Time_Per_Move = 0
5354 One_Time = 10
5455 Login_Time = 300 # time for LOGIN
55-Revision = "20170902"
56+Revision = "20180825"
5657
5758 RELOAD_FILES = ["shogi_server/league/floodgate.rb",
5859 "shogi_server/league/persistent.rb",
5960 "shogi_server/pairing.rb"]
6061 BASE_DIR = File.expand_path(File.dirname(__FILE__))
62+STOP_FILE = Pathname.new(BASE_DIR).join("STOP")
6163
6264 def reload
6365 RELOAD_FILES.each do |f|
@@ -66,6 +68,13 @@ def reload
6668 end
6769 module_function :reload
6870
71+##
72+# When the STOP file exists, starting a new game is not allowed.
73+def available?
74+ return !STOP_FILE.exist?
75+end
76+module_function :available?
77+
6978 class Logger < ::Logger
7079
7180 def initialize(logdev, shift_age = 0, shift_size = 1048576)
--- a/shogi_server/command.rb
+++ b/shogi_server/command.rb
@@ -497,7 +497,10 @@ module ShogiServer
497497 end
498498
499499 def call
500- if (! Login::good_game_name?(@game_name))
500+ if (!ShogiServer::available?)
501+ @player.write_safe("##[ERROR] As the service is going to shutdown shortly, starting new games is not allowed now.\n")
502+ return :continue
503+ elsif (! Login::good_game_name?(@game_name))
501504 @player.write_safe(sprintf("##[ERROR] bad game name: %s.\n", @game_name))
502505 if (/^(.+)-\d+-\d+F?$/ =~ @game_name)
503506 if Login::good_identifier?($1)
--- a/shogi_server/league/floodgate_thread.rb
+++ b/shogi_server/league/floodgate_thread.rb
@@ -103,7 +103,11 @@ module ShogiServer
103103
104104 next_instances = leagues.collect do |fg|
105105 unless (fg.next_time - Time.now) > 0
106- start_games(fg)
106+ if ShogiServer::available?
107+ start_games(fg)
108+ else
109+ log_message("The STOP file prevents from starting new Floodgate matches")
110+ end
107111 fg.charge # updates next_time
108112 end
109113 fg
Show on old repository browser