• R/O
  • HTTP
  • SSH
  • HTTPS

shogi-server: コミット

shogi-server source


コミットメタ情報

リビジョンc6ab4e68a7c76b1f8032f2310ed1c2a3af73383c (tree)
日時2018-08-26 12:14:53
作者Daigo Moriwaki <daigo@debi...>
コミッターDaigo Moriwaki

ログメッセージ

Merge remote-tracking branch 'origin/master'

変更サマリ

差分

--- a/changelog
+++ b/changelog
@@ -4,6 +4,10 @@
44 A file named "STOP" in the base directory prevents the server from
55 starting new games including Floodgate matches.
66 (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)
711
812 2018-04-07 Daigo Moriwaki <daigo at debian dot org>
913
--- a/shogi-server
+++ b/shogi-server
@@ -34,6 +34,8 @@ require 'shogi_server'
3434 require 'shogi_server/config'
3535 require 'shogi_server/util'
3636 require 'shogi_server/league/floodgate_thread.rb'
37+require 'pathname'
38+require 'set'
3739 require 'tempfile'
3840
3941 #################################################
@@ -271,6 +273,8 @@ def check_command_line
271273
272274 if $options["pid-file"]
273275 $options["pid-file"] = File.expand_path($options["pid-file"], $topdir)
276+ path = Pathname.new($options["pid-file"])
277+ path.dirname().mkpath()
274278 unless ShogiServer::is_writable_file? $options["pid-file"]
275279 usage
276280 $stderr.puts "Can not create the pid file: %s" % [$options["pid-file"]]
@@ -432,6 +436,9 @@ def main
432436
433437 $league.dir = $topdir
434438
439+ # Set of connected players
440+ $players = Set.new
441+
435442 config = {}
436443 config[:BindAddress] = "0.0.0.0"
437444 config[:Port] = port
@@ -459,8 +466,9 @@ def main
459466
460467 srand
461468 server = WEBrick::GenericServer.new(config)
462- ["INT", "TERM"].each do |signal|
469+ ["INT", "TERM"].each do |signal|
463470 trap(signal) do
471+ $players.each {|p| p.kill}
464472 server.shutdown
465473 setup_floodgate.kill
466474 end
@@ -492,6 +500,14 @@ def main
492500 log_message(sprintf("user %s login", player.name))
493501 login.process
494502 player.setup_logger($options["player-log-dir"]) if $options["player-log-dir"]
503+
504+ $mutex.lock
505+ begin
506+ $players.add(player)
507+ ensure
508+ $mutex.unlock
509+ end
510+
495511 player.run(login.csa_1st_str) # loop
496512 $mutex.lock
497513 begin
@@ -501,6 +517,7 @@ def main
501517 player.finish
502518 $league.delete(player)
503519 log_message(sprintf("user %s logout", player.name))
520+ $players.delete(player)
504521 ensure
505522 $mutex.unlock
506523 end
旧リポジトリブラウザで表示