[Ruby] Serv-O-Lux
0.5.0が公開された(ruby-talk:340522)。
デーモンプログラムやプロセスを扱うときに利用できるライブラリ。 1.8でも1.9でも、Ruby でも JRuby でも動作するそうです。
Child クラスのテストの追加他1つの修正。
適当に試してみた。かなりいい加減であまりよい例ではありません。
$ sudo gem install servolux
$ cat sample.rb
require 'servolux'
require 'logger'
$pwd = Dir.pwd
server = Servolux::Server.new('TimeStamp', :interval => 5, :logger=>Logger.new(STDOUT), :pid_file => $pwd + '/pid.txt')
class << server
def run()
open($pwd + "/timestamp.txt", "a+") {|ofs|
ofs.puts Time.now
ofs.flush
}
end
end
daemon = Servolux::Daemon.new(:server => server, :log_file => $pwd + '/sample.log')
daemon.startup
$ ruby sample.rb
D, [2009-07-01T21:35:37.012867 #4323] DEBUG -- : About to fork ...
D, [2009-07-01T21:35:37.022970 #4323] DEBUG -- : Waiting for "TimeStamp" to startup.
(しばらくすると)
...gems/servolux-0.5.0/lib/servolux/daemon.rb:367:in `wait_for_startup': \
"TimeStamp" failed to startup in a timely fashion. The timeout is set at \
30 seconds. (Servolux::Daemon::Timeout)
でも、デーモンとして動作しているので、別のターミナルで
$ tail -f timestamp.txt
2009-07-01 21:31:47 +0900
2009-07-01 21:31:52 +0900
2009-07-01 21:31:57 +0900
2009-07-01 21:32:02 +0900
....
でもって更に別のターミナルで
$ cat pid.txt
4332
$ ps -f -p 4332
UID PID PPID C STIME TTY TIME CMD
suke 4332 1 0 21:35 ? 00:00:00 ruby sample.rb
$ kill -9 4332
という訳で一応 Ruby 1.9.2dev でも動作するみたいですね。
| 固定リンク
この記事へのコメントは終了しました。
コメント