31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
|
# File 'lib/DrbDB.rb', line 31
def init
einfo("Memcached #{Memcached::VERSION}")
@cache = Memcached.new([@connection['cache_host']],{:prefix_key=>key_name, :default_ttl => 0, :timeout => 30})
DRb.start_service(@connection["uri"],self)
@server=DRb.current_server()
@main_server=DRb::DRbObject.new_with_uri(@main_server_uri)
@uri=server.uri()
unless init_sql(@connection['sql_host'],@connection['sql_user'],@connection['sql_password'],@connection['sql_db'])
eerror("connection to sql server failed: #{@connection['sql_user']}@#{@connection['sql_host']}/#{@connection['sql_db']}")
return nil
end
update_manqod_db
begin
begin
@admin=DRb::DRbObject.new(nil,@connection['admin_uri'])
we_have_admin=@admin.alive?
rescue
ewarn("no admin?")
sleep 1
end
end until we_have_admin
begin
@state=LOADING
load_all_attributes
admin.rows("select moditems.id,modules.modname,moditems.display from moditems left join modules on modules.id = moditems.modid").each{|moditem|
begin
case moditem["modname"]
when "listing"
@moditems[moditem["id"].to_i]=DrbListModel.new(self,moditem["id"].to_i).create_skeleton unless @moditems.has_key?(moditem["id"])
@moditems[moditem["id"].to_i].update(self)
when "form"
@moditems[moditem["id"].to_i]=DrbForm.new(self,moditem["id"].to_i).create_skeleton unless @moditems.has_key?(moditem["id"])
when "relation_builder"
@relation_builder=@moditems[moditem["id"].to_i]=DrbRelationBuilder.new(self,moditem["id"].to_i) unless @moditems.has_key?(moditem["id"])
else
ewarn("not caching #{moditem['display']}[#{moditem['modname']}]")
end
rescue =>err
ewarn("error loading moditem: #{moditem.inspect}")
eexception(err,:moditem => moditem)
end
}
@images=DrbImages.new(self).load_all
@users=Users.new(self).load_all
load_all_events
load_all_help
start_cron
@state=SERVING
rescue => err
eexception(err)
retry
end
DRb.thread.join
einfo("EXITED")
exit
end
|