# # Project <%= @conf.appname %> # # Created using bivouac on <%= Time.now %>. # Copyright (c) <%= Time.now.year %> __My__. All rights reserved. # # DO NOT EDIT THIS FILE OR YOU REALLY KNOW WHAT YOU ARE DOING # USE script/generate helper my_helper # windows_process = false if /Windows/.match( ENV['OS'] ) begin require 'win32/process' windows_process = true rescue LoadError => e warn "`win32-process' is not installed!" end end require 'simple-daemon' DIRNAME = File.expand_path( File.dirname(__FILE__) ) SimpleDaemon::WORKING_DIRECTORY = DIRNAME + "/../log/" class <%= @conf.appname %>Daemon < SimpleDaemon::Base @@server = nil @@use = nil def self.use=(x) @@use=x end def self.start config = Bivouac::Environment.new( ) database_connection = config.environment.db if database_connection[:adapter] =~ /sqlite/ database_connection[:database] = DIRNAME + "/../" + database_connection[:database] end <%= @conf.appname %>::Models::Base.establish_connection database_connection <%= @conf.appname %>::Models::Base.logger = Logger.new(DIRNAME + "/../log/<%= @conf.appname %>.log") # -- DON'T WORK WITH RAILS 2 -- # <%= @conf.appname %>::Models::Base.threaded_connections = false <%= @conf.appname %>.create if <%= @conf.appname %>.respond_to? :create trap(:INT) do stop end begin if @@use.nil? begin require 'thin' Rack::Handler::Thin.run Rack::Adapter::Camping.new( <%= @conf.appname %> ), :Host => config.environment.address, :Port => config.environment.port puts "** <%= @conf.appname %> is running at http://#{config.environment.address}:#{config.environment.port}" rescue LoadError require 'mongrel/camping' @@server = Mongrel::Camping.start( config.environment.address, config.environment.port, "/", <%= @conf.appname %>) puts "** <%= @conf.appname %> is running at http://#{config.environment.address}:#{config.environment.port}" @@server.run.join end else raise LoadError, "I want to use WEBrick please!" end rescue LoadError => e require 'webrick/httpserver' require 'camping/webrick' @@server = WEBrick::HTTPServer.new :BindAddress => config.environment.address, :Port => config.environment.port puts "** <%= @conf.appname %> is running at http://#{config.environment.address}:#{config.environment.port}" @@server.mount "/", WEBrick::CampingHandler, <%= @conf.appname %> @@server.start end end def self.stop begin @@server.stop rescue @@server.shutdown end @@server = nil end end while ARGV.size > 0 deamonize = ARGV.shift case deamonize when 'webrick' <%= @conf.appname %>Daemon.use='webrick' when '-c' ARGV.clear include <%= @conf.appname %>::Models config = Bivouac::Environment.new( ) database_connection = config.environment.db if database_connection[:adapter] =~ /sqlite/ database_connection[:database] = DIRNAME + "/../" + database_connection[:database] end <%= @conf.appname %>::Models::Base.establish_connection database_connection <%= @conf.appname %>.create if <%= @conf.appname %>.respond_to? :create require 'irb' require 'irb/completion' if File.exists? ".irbrc" ENV['IRBRC'] = ".irbrc" end IRB.start break when '-d' if /Windows/.match( ENV['OS'] ) and windows_process == false warn "You must install `win32-process' to daemonize this app." exit 1 end <%= @conf.appname %>Daemon.daemonize break when '-h' begin require 'mongrel/camping' puts "=> Booting Mongrel (use 'script/server webrick [options]' to force WEBrick)" rescue LoadError => e puts "=> Booting WEBrick" end puts "script/server [-d start|stop|restart] [-h]" exit when '--' <%= @conf.appname %>Daemon.start break else puts "Ignore unknown option '#{deamonize}' !" end end