# # Project <%= @appname %> # # Created using bivouac on <%= Time.now %>. # Copyright (c) <%= Time.now.year %> __My__. All rights reserved. # require 'simple-daemon' DIRNAME = File.expand_path( File.dirname(__FILE__) ) SimpleDaemon::WorkingDirectory = DIRNAME + "/../log/" class <%= @appname %>Daemon < SimpleDaemon::Base @@server = nil def self.start config = Bivouac::Environment.new( ) <%= @appname %>::Models::Base.establish_connection :adapter => 'sqlite3', :database => DIRNAME + "/../db/<%= @appname %>.db" <%= @appname %>::Models::Base.logger = Logger.new(DIRNAME + "/../log/<%= @appname %>.log") <%= @appname %>::Models::Base.threaded_connections = false <%= @appname %>.create if <%= @appname %>.respond_to? :create trap(:INT) do stop end begin require 'mongrel/camping' @@server = Mongrel::Camping.start( config.environment.address, config.environment.port, "/", <%= @appname %>) puts "** <%= @appname %> 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 "** <%= @appname %> is running at http://#{config.environment.address}:#{config.environment.port}" @@server.mount "/", WEBrick::CampingHandler, <%= @appname %> @@server.start end end def self.stop begin @@server.stop rescue @@server.shutdown end @@server = nil end end deamonize = ARGV.shift case deamonize when '-d' <%= @appname %>Daemon.daemonize when '-h' puts "script/server [-d start|stop|restart] [-h]" exit else <%= @appname %>Daemon.start end