26
27
28
29
30
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/gitdocs/manager.rb', line 26
def start(web_port)
Gitdocs.log_info("Starting Gitdocs v#{VERSION}...")
Gitdocs.log_info(
"Using configuration root: '#{Initializer.root_dirname}'"
)
Celluloid.boot unless Celluloid.running?
@supervisor = Celluloid::SupervisionGroup.run!
app =
Rack::Builder.new do
use Rack::Static,
urls: %w(/css /js /img /doc),
root: File.expand_path('../public', __FILE__)
use Rack::MethodOverride
map('/settings') { run SettingsApp }
map('/') { run BrowserApp }
end
@supervisor.add(
Reel::Rack::Server,
as: :reel_rack_server,
args: [
app,
{
Host: '127.0.0.1',
Port: web_port,
quiet: true
}
]
)
@synchronization_supervisor = Celluloid::SupervisionGroup.run!
Share.all.each do |share|
@synchronization_supervisor.add(
Synchronizer, as: share.id.to_s, args: [share]
)
end
@listener =
Listen.to(
*Share.paths,
ignore: /#{File::SEPARATOR}\.git#{File::SEPARATOR}/
) do |modified, added, removed|
all_changes = modified + added + removed
changed_repository_paths =
Share.paths.select do |directory|
all_changes.any? { |x| x.start_with?(directory) }
end
changed_repository_paths.each do |directory|
actor_id = Share.find_by_path(directory).id.to_s
Celluloid::Actor[actor_id].async.synchronize
end
end
@listener.start
sleep
rescue Interrupt, SystemExit
Gitdocs.log_info('Interrupt received...')
rescue Exception => e Gitdocs.log_error(
"#{e.class.inspect} - #{e.inspect} - #{e.message.inspect}"
)
Gitdocs.log_error(e.backtrace.join("\n"))
Notifier.error(
'Unexpected exit',
'Something went wrong. Please see the log for details.'
)
raise
ensure
Gitdocs.log_info('stopping listeners...')
@listener.stop if @listener
Gitdocs.log_info('stopping synchronizers...')
@synchronization_supervisor.terminate if @synchronization_supervisor
Gitdocs.log_info('terminate supervisor...')
@supervisor.terminate if @supervisor
Gitdocs.log_info('disconnect notifier...')
Notifier.disconnect
Gitdocs.log_info("Gitdocs is terminating...goodbye\n\n")
end
|