# # Project BivouacSample # # Created using bivouac on Mon Sep 10 21:47:54 +0200 2007. # Copyright (c) 2007 __My__. All rights reserved. # require 'simple-daemon' DIRNAME = File.expand_path( File.dirname(__FILE__) ) SimpleDaemon::WorkingDirectory = DIRNAME + "/../log/" class BivouacSampleDaemon < SimpleDaemon::Base @@server = nil def self.start config = Bivouac::Environment.new( ) BivouacSample::Models::Base.establish_connection :adapter => 'sqlite3', :database => DIRNAME + "/../db/BivouacSample.db" BivouacSample::Models::Base.logger = Logger.new(DIRNAME + "/../log/BivouacSample.log") # BivouacSample::Models::Base.threaded_connections = false BivouacSample.create if BivouacSample.respond_to? :create trap(:INT) do stop end begin require 'mongrel/camping' @@server = Mongrel::Camping.start( config.environment.address, config.environment.port, "/", BivouacSample) puts "** BivouacSample is running at http://#{config.environment.address}:#{config.environment.port}" @@server.run.join rescue LoadError => e require 'webrick/httpserver' require 'camping/webrick' @@server = WEBrick::HTTPServer.new :BindAddress => config.environment.address, :Port => config.environment.port puts "** BivouacSample is running at http://#{config.environment.address}:#{config.environment.port}" @@server.mount "/", WEBrick::CampingHandler, BivouacSample end end def self.stop begin @@server.stop rescue @@server.shutdown end @@server = nil end end deamonize = ARGV.shift case deamonize when '-d' BivouacSampleDaemon.daemonize when '-h' puts "script/server [-d start|stop|restart] [-h]" exit else BivouacSampleDaemon.start end