require 'shogi_server/config'
require 'shogi_server/util'
require 'shogi_server/league/floodgate_thread.rb'
+require 'pathname'
+require 'set'
require 'tempfile'
#################################################
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
if $options["pid-file"]
$options["pid-file"] = File.expand_path($options["pid-file"], $topdir)
+ path = Pathname.new($options["pid-file"])
+ path.dirname().mkpath()
unless ShogiServer::is_writable_file? $options["pid-file"]
usage
$stderr.puts "Can not create the pid file: %s" % [$options["pid-file"]]
$league.dir = $topdir
+ # Set of connected players
+ $players = Set.new
+
config = {}
- config[:BindAddress] = "0.0.0.0"
+ config[:BindAddress] = nil # both IPv4 and IPv6
config[:Port] = port
config[:ServerType] = WEBrick::Daemon if $options["daemon"]
config[:Logger] = $logger
srand
server = WEBrick::GenericServer.new(config)
- ["INT", "TERM"].each do |signal|
+ ["INT", "TERM"].each do |signal|
trap(signal) do
+ $players.each {|p| p.kill}
server.shutdown
setup_floodgate.kill
end
$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
log_message(sprintf("user %s login", player.name))
login.process
player.setup_logger($options["player-log-dir"]) if $options["player-log-dir"]
+
+ $mutex.lock
+ begin
+ $players.add(player)
+ ensure
+ $mutex.unlock
+ end
+
player.run(login.csa_1st_str) # loop
$mutex.lock
begin
player.finish
$league.delete(player)
log_message(sprintf("user %s logout", player.name))
+ $players.delete(player)
ensure
$mutex.unlock
end