質問編集履歴
1
g
test
CHANGED
File without changes
|
test
CHANGED
@@ -49,3 +49,107 @@
|
|
49
49
|
/var/www/baseball-app/shared/bundle/ruby/2.5.0/bin/unicorn:23:in `<top (required)>'
|
50
50
|
|
51
51
|
```
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
unicorn.rb
|
58
|
+
|
59
|
+
```
|
60
|
+
|
61
|
+
#サーバ上でのアプリケーションコードが設置されているディレクトリを変数に入れておく
|
62
|
+
|
63
|
+
app_path = File.expand_path('../../', __FILE__)
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
#アプリケーションサーバの性能を決定する
|
68
|
+
|
69
|
+
worker_processes 1
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
#アプリケーションの設置されているディレクトリを指定
|
74
|
+
|
75
|
+
working_directory app_path
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
#Unicornの起動に必要なファイルの設置場所を指定
|
80
|
+
|
81
|
+
pid "#{app_path}/tmp/pids/unicorn.pid"
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
stderr_path "#{app_path}/log/unicorn.stderr.log"
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
stdout_path "#{app_path}/log/unicorn.stdout.log"
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
timeout 60
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
preload_app true
|
98
|
+
|
99
|
+
GC.respond_to?(:copy_on_write_friendly=) && GC.copy_on_write_friendly = true
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
check_client_connection false
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
run_once = true
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
before_fork do |server, worker|
|
112
|
+
|
113
|
+
defined?(ActiveRecord::Base) &&
|
114
|
+
|
115
|
+
ActiveRecord::Base.connection.disconnect!
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
if run_once
|
120
|
+
|
121
|
+
run_once = false # prevent from firing again
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
old_pid = "#{server.config[:pid]}.oldbin"
|
128
|
+
|
129
|
+
if File.exist?(old_pid) && server.pid != old_pid
|
130
|
+
|
131
|
+
begin
|
132
|
+
|
133
|
+
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
|
134
|
+
|
135
|
+
Process.kill(sig, File.read(old_pid).to_i)
|
136
|
+
|
137
|
+
rescue Errno::ENOENT, Errno::ESRCH => e
|
138
|
+
|
139
|
+
logger.error e
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
after_fork do |_server, _worker|
|
150
|
+
|
151
|
+
defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
```
|