ruby-reference-manual:691
From: Yugui <yugui@y...>
Date: Wed, 23 Jan 2008 11:45:50 +0900
Subject: [ruby-reference-manual:691] bitclust/standalone --pid-file
Yuguiです。 bitclust/standalone.rbに、pidを記録するオプションを付け てみました。 Index: standalone.rb =================================================================== --- standalone.rb (revision 2447) +++ standalone.rb (working copy) @@ -25,9 +25,10 @@ debugp = false autop = false browser = nil +pid_file = nil parser = OptionParser.new -parser.banner = "#{$0} [--bind-address=ADDR] [--port=NUM] -- baseurl=URL --database=PATH [--srcdir=PATH] [--templatedir=PATH] [-- themedir=PATH] [--debug] [--auto] [--browser=BROWSER]" +parser.banner = "#{$0} [--bind-address=ADDR] [--port=NUM] -- baseurl=URL --database=PATH [--srcdir=PATH] [--templatedir=PATH] [-- themedir=PATH] [--debug] [--auto] [--browser=BROWSER] [--pid-file=PATH]" parser.on('--bind-address=ADDR', 'Bind address') {|addr| params[:BindAddress] = addr } @@ -58,6 +59,9 @@ parser.on('--browser=BROWSER', 'Open with the browser.') {|path| browser = path } +parser.on('--pid-file=PATH', 'Write pid of the daemon to the specified file.') {|path| + pid_file = path +} parser.on('--help', 'Prints this message and quit.') { puts parser.help exit 0 @@ -147,7 +151,16 @@ if debugp trap(:INT) { server.shutdown } else - WEBrick::Daemon.start + WEBrick::Daemon.start do + trap(:TERM) { + server.shutdown + begin + File.unlink pid_file if pid_file + rescue Errno::ENOENT + end + } + File.open(pid_file, 'w') {|f| f.write Process.pid } if pid_file + end end exit if $".include?("exerb/mkexy.rb") if autop && !browser -- Yugui yugui@y... http://idm.s9.xrea.com -- ML: ruby-reference-manual@m... 使い方: http://QuickML.com/