48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/arldap/server.rb', line 48
def start
pidfile.ensure_empty! "ERROR: It looks like I'm already running #{@config['pid_file']}. Not starting."
logger.info "Starting LDAP server"
daemonize(logger)
self.logger.info("Cannot load Rails. Exiting.") and exit 5 unless defined? RAILS_ROOT
@config.symbolize_keys!
logger.info "Became daemon with process id: #{$$}"
begin
pidfile.create
rescue Exception => e
logger.info "Exception caught while creating pidfile: #{e}"
exit
end
trap("TERM") do
logger.info("Received TERM signal. Exiting.") if logger
pidfile.remove if pidfile
exit
end
begin
rescue Exception => e
logger.info "Exception caught: #{e}"
exit
end
klass = nil
begin
klass = @config[:active_record_model].constantize
logger.info "Access to #{klass.count} #{@config[:active_record_model]} records"
rescue Exception => e
logger.info "Exception caught while loading #{@config[:active_record_model]}: #{e}"
exit
end
s = LDAP::Server.new(
:port => @config[:port],
:bindaddr => @config[:bind_address],
:nodelay => @config[:tcp_nodelay],
:listen => @config[:prefork_threads],
:namingContexts => [@config[:basedn]],
:user => @config[:user],
:group => @config[:group],
:operation_class => ActiveRecordOperation,
:operation_args => [@config, klass, logger]
)
s.run_tcpserver
logger.info "Listening on port #{@config[:port]}."
s.join
end
|