0
votes

I am setting up VPS for the first time on upcloud. I am using unicorn 5.5.5 with Nginx. Rails 4.2.8 and ruby 2.4.2. My Nginx service runs fine. Doesn't show any error. Whenever I start unicorn service I get this error. I followed this tutorial.

https://medium.com/@manishyadavv/how-to-deploy-ruby-on-rails-apps-on-aws-ec2-7ce55bb955fa

F, [2020-06-16T12:44:20.611895 #12683] FATAL -- : error adding listener addr=/tmp/unicorn.sock
/usr/share/rvm/gems/ruby-2.4.2/gems/unicorn-5.5.5/lib/unicorn/socket_helper.rb:132:in `bind_listen': socket=/tmp/unicorn.sock specified but it is not a socket! (ArgumentError)
        from /usr/share/rvm/gems/ruby-2.4.2/gems/unicorn-5.5.5/lib/unicorn/http_server.rb:243:in `listen'
        from /usr/share/rvm/gems/ruby-2.4.2/gems/unicorn-5.5.5/lib/unicorn/http_server.rb:851:in `block in bind_new_listeners!'
        from /usr/share/rvm/gems/ruby-2.4.2/gems/unicorn-5.5.5/lib/unicorn/http_server.rb:851:in `each'
        from /usr/share/rvm/gems/ruby-2.4.2/gems/unicorn-5.5.5/lib/unicorn/http_server.rb:851:in `bind_new_listeners!'
        from /usr/share/rvm/gems/ruby-2.4.2/gems/unicorn-5.5.5/lib/unicorn/http_server.rb:142:in `start'
        from /usr/share/rvm/gems/ruby-2.4.2/gems/unicorn-5.5.5/bin/unicorn:128:in `<top (required)>'
        from /usr/share/rvm/gems/ruby-2.4.2/bin/unicorn:23:in `load'
        from /usr/share/rvm/gems/ruby-2.4.2/bin/unicorn:23:in `<main>'
        from /usr/share/rvm/gems/ruby-2.4.2/bin/ruby_executable_hooks:24:in `eval'
        from /usr/share/rvm/gems/ruby-2.4.2/bin/ruby_executable_hooks:24:in `<main>'

My unicorn.sock file is empty, I am sorry if this is a rookie mistake but I am stuck with this issue for 2 days now. Kindly help me out. Here is my unicorn_repo file in the etc/init.d directory

#!/bin/sh
### BEGIN INIT INFO
# Provides:          unicorn
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the unicorn app server
# Description:       starts unicorn using start-stop-daemon
### END INIT INFO
set -e
USAGE="Usage: $0 <start|stop|restart|upgrade|rotate|force-stop>"
# app settings
USER="root"
APP_NAME="soup"
APP_ROOT="/$USER/$APP_NAME"
ENV="production"
# environment settings
PATH="/home/$USER/.rbenv/shims:/home/$USER/.rbenv/bin:$PATH"
CMD="cd $APP_ROOT && bundle exec unicorn -c config/unicorn.rb -E $ENV -D"
PID="$APP_ROOT/shared/pids/unicorn.pid"
OLD_PID="$PID.oldbin"

here is my nginx/default file

upstream app {
    # Path to Unicorn SOCK file, as defined previously
    server unix:/tmp/unicorn.sock fail_timeout=0;
}
server {
    listen 0.0.0.0;
    server_name localhost;
    root root/soup/;
    try_files $uri/index.html $uri @app;
    location @app {
        proxy_pass http://app;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
    }
    error_page 500 502 503 504 /500.html;
    client_max_body_size 4G;
    keepalive_timeout 10;
}

Here is my unicorn.rb file.

# set path to application
app_dir = File.expand_path("../..", __FILE__)
shared_dir = "#{app_dir}/shared"
working_directory app_dir
# Set unicorn options
worker_processes 2
preload_app true
timeout 30
# Set up socket location
listen "/tmp/unicorn.sock", :backlog => 64
listen 3000, :tcp_nopush => true

# Logging
stderr_path "#{shared_dir}/log/unicorn.stderr.log"
stdout_path "#{shared_dir}/log/unicorn.stdout.log"
# Set master PID location
pid "#{shared_dir}/pids/unicorn.pid"
~
~
~
~
1
I am not 100% sure, but I don't like one thing: in your unicorn init file you are using USER=root. First, a good advice is to always use an user different from root. Also, the default user for EC2 instances usually is ubuntu. Try changing that. If don't work, try moving the socket path from /tmp/unicorn.sock to another one, for example /home/ubuntu/unicorn.sock. And if nothing works, add your config/unicorn.rb file too to the question.cmramseyer
I have added the unicorn.rb . Sir why it says "its not a socket, I feel like there should be some code in unicorn.sock but its empty". What you think ?Muhammad Hamza Altaf

1 Answers

0
votes

A socket is a special kind of file used for inter process communication. If you you run ls -la sockets have a leading s in the mode string.

Yours should look something like this:

srwxrwxrwx /tmp/unicorn.sock

If you have created /tmp/unicorn.sock as a file manually, delete it.

As a side note: The tutorial you are using is 3 years old and so your setup is outdated from the start.