A
A
Alexander Petrov2015-10-02 13:37:10
Nginx
Alexander Petrov, 2015-10-02 13:37:10

Can't start unicorn. It gives an error, how to fix it?

And so, perhaps, I will tell you what actions I performed and what I came to. I look forward to your help and moral support.
1) I bought a server with centos7 installed.
2) Installed nginx, rvm, ruby, rails. created an application in /home/petrov/lessonweb/ folder
3) added unicorn and therubyracer gems, bundle install. All OK.
4) I added the unicorn.rb file and wrote the following there:

worker_processes 2
working_directory "/home/petrov/lessonweb/"

preload_app true

timeout 30

listen "/home/petrov/lessonweb/tmp/sockets/unicorn.sock", :backlog => 64

pid "/home/petrov/lessonweb/tmp/pids/unicorn.pid"

stderr_path "/home/petrov/lessonweb/log/unicorn.stderr.log"
stdout_path "/home/petrov/lessonweb/log/unicorn.stdout.log"

before_fork do |server, worker|
    defined?(ActiveRecord::Base) and
        ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|
    defined?(ActiveRecord::Base) and
        ActiveRecord::Base.establish_connection
end

5) launched:
unicorn_rails -c config/unicorn.rb -E production -D

no one cursed at anything, thought that everything was fine, went on to configure nginx
6) Created a file /etc/nginx/conf.d/lesson-web.conf and wrote the following lines:
upstream lessonweb {
  server unix: /home/petrov/lessonweb/tmp/sockets/unicorn.sock;
}

server {
    listen 80;
    server_name lesson-web www.lesson-web.ru;

    location / {

        root /home/petrov/lessonweb/public;

        if (!-f $request_filename) {
            #делаем проксипасс на первый поток "project"
            proxy_pass http://lessonweb; 
            break;
        }
    }

}

7) restarted nginx, run
unicorn_rails -c config/unicorn.rb -E production -D

and the terminal outputs this:
master failed to start, check stderr log for details

We look at the logs: (I open the logs here /home/perov/lessonweb/log/unicorn.stderr.log right?)
They write this:
I, [2015-10-02T13:09:20.083650 #25092]  INFO -- : Refreshing Gem list
I, [2015-10-02T13:09:21.289238 #25092]  INFO -- : listening on addr=/home/petrov/lessonweb/tmp/sockets/unicorn.sock fd=11
I, [2015-10-02T13:09:21.293355 #25092]  INFO -- : master process ready
I, [2015-10-02T13:09:21.308838 #25095]  INFO -- : worker=0 ready
I, [2015-10-02T13:09:21.313020 #25097]  INFO -- : worker=1 ready
/usr/local/rvm/gems/ruby-2.2.2/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:206:in `pid=': Already running on PID:25092 (or pid=/home/petrov/lessonweb/tmp/pids/unicorn.pid is stale) (ArgumentError)
  from /usr/local/rvm/gems/ruby-2.2.2/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:135:in `start'
  from /usr/local/rvm/gems/ruby-2.2.2/gems/unicorn-4.9.0/bin/unicorn_rails:209:in `<top (required)>'
  from /usr/local/rvm/gems/ruby-2.2.2/bin/unicorn_rails:23:in `load'
  from /usr/local/rvm/gems/ruby-2.2.2/bin/unicorn_rails:23:in `<main>'
  from /usr/local/rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `eval'
  from /usr/local/rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `<main>'

What does this all mean and what should be done next?
Thanks in advance)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
EvgeniyKonstantinov, 2015-10-02
@Mirkom63

So it seems that everything is written in the log. If there is no second unicorn, then just delete the remaining pid file.
This is confusing:

7) reloaded nginx, run
unicorn_rails -c config/unicorn.rb -E production -D

Did you try to start the second instance of unicorn on purpose or forgot to stop the previous one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question