2008-02-04 Daigo Moriwaki <daigo at debian dot org>
* [shogi-server]
- - In the daemon mode, if the specified directory was a relative
- path, the server could fail to start with a permission denied
- error. This issue has been fixed. The path is interpreted as
- an absolute path before switching to daemon.
-
* [webserver]
- In the daemon mode, if the specified directory was a relative
path, the server could fail to start with a permission denied
error. This issue has been fixed. The path is interpreted as
an absolute path before switching to daemon.
+ - In the daemon mode, a wrong process id was written in
+ '--pid-file'. This issue has been fixed. Also, the pid file
+ will be removed when the server shuts down.
2008-02-03 Daigo Moriwaki <daigo at debian dot org>
def write_pid_file(file)
open(file, "w") do |fh|
- fh.print Process::pid, "\n"
+ fh.puts "#{$$}"
end
end
LEAGUE.event = ARGV.shift
port = ARGV.shift
- write_pid_file($options["pid-file"]) if ($options["pid-file"])
-
- dir = $options["daemon"] || nil
+ dir = $options["daemon"]
dir = File.expand_path(dir) if dir
if dir && ! File.exist?(dir)
FileUtils.mkdir(dir)
config[:Port] = port
config[:ServerType] = WEBrick::Daemon if $options["daemon"]
config[:Logger] = $logger
+ if $options["pid-file"]
+ pid_file = File.expand_path($options["pid-file"])
+ config[:StartCallback] = Proc.new do
+ write_pid_file(pid_file)
+ end
+ config[:StopCallback] = Proc.new do
+ FileUtils.rm(pid_file, :force => true)
+ end
+ end
server = WEBrick::GenericServer.new(config)
["INT", "TERM"].each do |signal|
require 'thread'
require 'webrick'
require 'socket'
+require 'fileutils'
+
+def write_pid_file(file)
+ open(file, "w") do |fh|
+ fh.puts "#{$$}"
+ end
+end
class ShogiClient
CLIENT_NAME = "web"
def usage
$stderr.puts <<-EOF
-USAGE: #{$0} [--daemon dir] [--port port]
+USAGE: #{$0} [--daemon dir] [--port port] [--pid-file file]
--daemon dir Run as a daemon. Log files are put in dir
--port port Listening port for HTTP server (default 4080)
+ --pid-file file Write the process id to the file
EOF
end
def parse_command_line
options = Hash::new
- parser = GetoptLong.new( ["--daemon", GetoptLong::REQUIRED_ARGUMENT],
- ["--port", GetoptLong::REQUIRED_ARGUMENT])
+ parser = GetoptLong.new( ["--daemon", GetoptLong::REQUIRED_ARGUMENT],
+ ["--port", GetoptLong::REQUIRED_ARGUMENT],
+ ["--pid-file", GetoptLong::REQUIRED_ARGUMENT])
parser.quiet = true
begin
parser.each_option do |name, arg|
raise parser.error_message
end
- dir = options["daemon"] || nil
+ dir = options["daemon"]
dir = File.expand_path(dir) if dir
if dir && ! File.exist?(dir)
FileUtils.mkdir(dir)
end
options["dir"] = dir || File.dirname(__FILE__)
-
options["port"] ||= 4080
options["port"] = options["port"].to_i
-
+ options["pid-file"] = File.expand_path(options["pid-file"]) if options["pid-file"]
+
return options
end
http_config[:Logger] = WEBrick::Log.new(http_log_file)
http_config[:AccessLog] =
[[ WEBrick::Log.new(http_access_log_file), WEBrick::AccessLog::COMMON_LOG_FORMAT ]]
+ if $options["pid-file"]
+ http_config[:StartCallback] = Proc.new do
+ write_pid_file($options["pid-file"])
+ end
+ http_config[:StopCallback] = Proc.new do
+ FileUtils.rm($options["pid-file"], :force => true)
+ end
+ end
+
server = WEBrick::HTTPServer.new(http_config)