Sha256: e6a8266416a36f8b39841e6589496249084c94740e4ad9c6f95e37bb7eda7069

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

Contents

#
# daemon.rb
#
#   Copyright (c) 1999-2002 Minero Aoki <aamine@loveruby.net>
#
#   This program is free software.
#   You can distribute/modify this program under the terms of
#   the GNU Lesser General Public License version 2 or later.
#
#   $Id: daemon.rb,v 1.2 2002/01/05 06:19:34 aamine Exp $
#

require 'socket'


class Daemon

  def self.exec( port, dir, debug = $DEBUG )
    new(debug).exec port, dir
  end

  def initialize( debug = $DEBUG )
    @debug = $DEBUG
  end

  def exec( port, dir )
    if @debug then
      Dir.chdir dir
      wait 
      return
    end

    fork do
      Process.setsid
      fork do
        Dir.chdir dir
        $stdin.close
        $stdout.close
        $stderr.close

        wait
      end

      exit!
    end
    exit!
  end

  def wait
    s = TCPServer.new( 10070 )

    unless @debug then
      trap( 'SIGINT' ) { exit! }
      trap( 'SIGHUP' ) { exit! }
      trap( 'SIGTERM' ) { exit! }
    end

    while true do
      @sock = s.accept
      begin
        session
      ensure
        @sock.close
      end
    end
  end

  # abstract session

end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
carats-0.3.0 lib/carat-dev/daemon/daemon.rb
facets-1.4.2 forge/more/daemon.rb
facets-1.4.1 forge/more/daemon.rb
facets-1.4.3 forge/more/daemon.rb
facets-1.4.4 forge/more/daemon.rb
facets-1.4.5 snip/more/daemon.rb
facets-1.8.49 work/more/daemon.rb
facets-1.8.0 work/more/daemon.rb
facets-1.8.20 work/more/daemon.rb
facets-1.8.8 work/more/daemon.rb