From: "Ara.T.Howard" Date: 2005-11-08T03:42:05+09:00 Subject: Re: Daemons written in ruby... On Tue, 8 Nov 2005, Steve [RubyTalk] wrote: > I've written a simple daemon as a ruby script... it writes all interesting > output to a log file and is intended to be a long-running process as opposed > to a program which executes only while a user is logged in. > > In C I'd have closed stdin, stdout and stderr; dissociate my process from its > parent then called fork in order to return 0 indicate successfully starting > the daemon. > > What is the best way to achieve this in Ruby? I can achieve the end result I > want using nohup, but I'm sure there must be a neater way. runs any command line as a daemon. also sets the name that appears in top/ps. #! /home/ahoward/bin/ruby fork{ stdin = open '/dev/null', 'r' stdout = open '/dev/null', 'w' stderr = open '/dev/null', 'w' STDIN.reopen stdin STDOUT.reopen stdout STDERR.reopen stderr $0 = ARGV.first || $0 fork{ command = ARGV.join ' ' system(command) ? exit : abort } and exit! } -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | anything that contradicts experience and logic should be abandoned. | -- h.h. the 14th dalai lama ===============================================================================