OSDN Git Service

Debugged the daemon mode
authorbeatles <beatles@b8c68f68-1e22-0410-b08e-880e1f8202b4>
Tue, 7 Oct 2008 13:11:51 +0000 (13:11 +0000)
committerbeatles <beatles@b8c68f68-1e22-0410-b08e-880e1f8202b4>
Tue, 7 Oct 2008 13:11:51 +0000 (13:11 +0000)
shogi-server
shogi_server.rb
shogi_server/league.rb

index 1f5a9f5..771936d 100755 (executable)
@@ -18,6 +18,7 @@
 ## along with this program; if not, write to the Free Software
 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+TOP_DIR = File.expand_path(File.dirname(__FILE__))
 $:.unshift File.dirname(__FILE__)
 require 'shogi_server'
 
@@ -220,8 +221,6 @@ end
 
 def main
   
- setup_watchdog_for_giant_lock
-
   $options = parse_command_line
   if (ARGV.length != 2)
     usage
@@ -235,6 +234,9 @@ def main
     usage
     exit 3
   end
+  if $options["pid-file"] 
+    $options["pid-file"] = File.expand_path($options["pid-file"])
+  end
 
   LEAGUE.event = ARGV.shift
   port = ARGV.shift
@@ -248,8 +250,7 @@ def main
   log_file = dir ? File.join(dir, "shogi-server.log") : STDOUT
   $logger = setup_logger(log_file)
 
-  LEAGUE.dir = dir || File.dirname(__FILE__)
-  LEAGUE.setup_players_database
+  LEAGUE.dir = dir || TOP_DIR
 
   config = {}
   config[:Port]       = port
@@ -257,16 +258,19 @@ def main
   config[:Logger]     = $logger
 
   fg_thread = nil
+
   config[:StartCallback] = Proc.new do
     if $options["pid-file"]
       write_pid_file($options["pid-file"])
     end
+    setup_watchdog_for_giant_lock
+    LEAGUE.setup_players_database
     fg_thread = setup_floodgate
   end
 
   config[:StopCallback] = Proc.new do
     if $options["pid-file"]
-      FileUtils.rm(pid_file, :force => true)
+      FileUtils.rm($options["pid-file"], :force => true)
     end
   end
 
@@ -316,7 +320,7 @@ if ($0 == __FILE__)
   Thread.abort_on_exception = $DEBUG ? true : false
 
   begin
-  LEAGUE = ShogiServer::League::new
+    LEAGUE = ShogiServer::League.new(TOP_DIR)
     main
   rescue Exception => ex
     log_error("main: #{ex.class}: #{ex.message}\n\t#{ex.backtrace[0]}")
index 8f0b49b..4b1b39a 100644 (file)
@@ -58,7 +58,7 @@ RELOAD_FILES = ["shogi_server/league/floodgate.rb",
                 "shogi_server/pairing.rb"]
 
 def reload
-  here = File.dirname(__FILE__)
+  here = TOP_DIR || File.dirname(__FILE__)
   RELOAD_FILES.each do |f|
     load File.join(here, f)
   end
index 29d7bf2..9f7a5f3 100644 (file)
@@ -26,12 +26,12 @@ module ShogiServer # for a namespace
 #
 class League
 
-  def initialize
+  def initialize(dir=File.dirname(__FILE__))
     @mutex = Monitor.new # guard @players
     @games = Hash::new
     @players = Hash::new
     @event = nil
-    @dir = File.dirname(__FILE__)
+    @dir = dir
   end
   attr_accessor :players, :games, :event, :dir