]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
+ pidfile support + command line option for pid file name
authorDmitry Kim <dmitry point kim at gmail point com>
Sat, 21 Apr 2007 17:58:25 +0000 (17:58 +0000)
committerDmitry Kim <dmitry point kim at gmail point com>
Sat, 21 Apr 2007 17:58:25 +0000 (17:58 +0000)
bin/rbot
lib/rbot/ircbot.rb

index 95076eb3911abd64c1d032ab9249cda1797fc54a..0a8fb7e9637dfa76ee175dfa7abb3e2db925e699 100755 (executable)
--- a/bin/rbot
+++ b/bin/rbot
@@ -68,6 +68,7 @@ opts = GetoptLong.new(
   ["--help",  "-h", GetoptLong::NO_ARGUMENT],
   ["--loglevel",  "-l", GetoptLong::REQUIRED_ARGUMENT],
   ["--trace",  "-t", GetoptLong::REQUIRED_ARGUMENT],
+  ["--pidfile", "-p", GetoptLong::REQUIRED_ARGUMENT],
   ["--version", "-v", GetoptLong::NO_ARGUMENT]
 )
 
@@ -117,6 +118,7 @@ if ($opts["help"])
   puts "  -v, --version      version information"
   puts "  -d, --debug        enable debug messages"
   puts "  -b, --background   background (daemonize) the bot"
+  puts "  -p, --pidfile      write the bot pid to this file"
   puts "config directory defaults to ~/.rbot"
   exit 0
 end
index b1ffb51f3048c36ed95ae23d753afa2a35aeb37a..f4c1f5bcabb3e7d25e30f3014d079106d6fc5548 100644 (file)
@@ -429,6 +429,10 @@ class Bot
 
     log_session_start
 
+    File.open($opts['pidfile'] || "#{@botclass}/rbot.pid", 'w') do |pf|
+      pf << "#{$$}\n"
+    end
+
     @registry = BotRegistry.new self
 
     @timer = Timer::Timer.new(1.0) # only need per-second granularity