#!/usr/bin/env ruby231 # ypdmd -- ydim -- 12.01.2005 -- hwyss@ywesee.com require 'yaml' require 'syck' require 'ydim/server' require 'ydim/odba' require 'logger' require 'rclconf' require 'drb' require 'fileutils' require 'odba/connection_pool' require 'odba/drbwrapper' require 'pg' require 'dbi' require 'dbi/version' require 'dbd/Pg' $0 = __FILE__ config = YDIM::Server.config ODBA.storage.dbi = ODBA::ConnectionPool.new(config.db_driver_url, config.db_user, config.db_auth, :client_encoding => 'LATIN1') ODBA.cache.setup DRb.install_id_conv ODBA::DRbIdConv.new log_file = config.log_file if(log_file.is_a?(String)) FileUtils.mkdir_p(File.dirname(log_file)) log_file = File.open(log_file, 'a') at_exit { log_file.close } end logger = Logger.new(log_file) logger.level = Logger.const_get(config.log_level) server = YDIM::Server.new(config, logger) server.extend(DRbUndumped) if(config.detach) pidfile = '/var/run/ydimd.pid' File.open(pidfile, 'w') { |fh| fh.puts $$ } at_exit { File.unlink(pidfile) } Process.fork and exit!(0) end begin url = config.server_url url.untaint DRb.start_service(url, server) $SAFE = 1 logger.info('start') { sprintf("starting ydim-server on %s", config.server_url) } DRb.thread.join rescue Exception => error logger.error('fatal') { error } raise end