From: "Iñaki Baz Castillo" Date: 2009-12-13T08:51:02+09:00 Subject: Re: Is it possible to force a Ruby program to run as a proc name different than "ruby"? El Sábado, 12 de Diciembre de 2009, Robert Klemme escribió: > This is what I would do: > > VAR='/var/run' > > pid_file = File.join(VAR, File.basename($0) + '.pid') > > begin > old_pid = File.read(pid_file).to_i > Process.kill 0, old_pid > $stderr.puts "ERROR: already running with PID #{old_pid}" > exit 1 > rescue Errno::ENOENT > # no pid file > rescue Errno::ESRCH > # process not running > $stderr.puts 'WARNING: stale pid file' > end > > # open file with EXCL in order to catch race conditions where two > # processes were started almost at the same time and both thought > # they would be a new instance. Uncomment sleep to simulate: > # sleep 2 > File.open(pid_file, File::EXCL | File::WRONLY | File::CREAT) {|io| > io.write($$)} > trap(0) {File.delete pid_file} > > puts "OK, here we go." Let me a question: is the above a fragment of a Linux init script written in Ruby (rather than bash/sh as usual)? If so, according to LSB specifications it should return 0 (success) in case of "start" action when the daemon is already running. Thanks a lot. -- Iñaki Baz Castillo