65
62

More than 5 years have passed since last update.

Ruby スクリプトをDaemon化する簡単な方法

Posted at

[ruby]僕たちが待ち望んでいたRubyスクリプトをデーモン化する方法

のまんま転記なのだけれど、わすれないように、メモ

ruby 1.9からは下記Methodが使える
これをスクリプトの先頭に加える

foo.rb
Process.daemon

簡単に、Daemon or not を切り替えるために

daemonize.rb
Process.daemon

と書いておいて、require "daemnize" とよびだせるようにしておくと、起動オプションで、切りかえ可能になる。

ruby -r daemonize foo.rb

や、この -r option で、処理を切り替えるやりかたは、いろいろ応用できそう。勉強になりました!

65
62
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
65
62