forked from wikimedia/mediawiki-services-mathoid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
unicorn.rb
40 lines (33 loc) · 1.13 KB
/
unicorn.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
PROJECT_ROOT = File.expand_path(File.dirname(__FILE__))
MATHOID_FILES = '/srv/mathoid'
MATHOID_PORT = ENV['MATHOID_PORT'] || 7090
IS_LOCAL = ENV['RACK_ENV'] == 'development'
working_directory PROJECT_ROOT
worker_processes IS_LOCAL ? 2 : 4
preload_app false
# Set a higher timeout when in vagrant VM, otherwise the workers are killed by
# timeout when sprockets compiles the assets
timeout IS_LOCAL ? 300 : 30
listen "127.0.0.1:#{MATHOID_PORT}"
pid MATHOID_FILES + "/pids/unicorn-#{MATHOID_PORT}.pid"
stderr_path MATHOID_FILES + "/log/error-#{MATHOID_PORT}.log"
stdout_path MATHOID_FILES + "/log/access-#{MATHOID_PORT}.log"
before_fork do |server, worker|
old_pid = MATHOID_FILES + "/pids/unicorn-#{MATHOID_PORT}.oldbin"
if File.exists?(old_pid) && server.pid != old_pid
begin
Process.kill('QUIT', File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
# someone else did our job for us
end
end
sleep 1
end
after_fork do |server, worker|
port = (rand * 1000 + 10000).to_i
ENV['PHANTOM_PORT'] = port.to_s
phantom_job = fork do
exec "PORT=#{port} phantomjs ./mathjax.js"
end
Process.detach(phantom_job)
end