Configuring the EC2 Rails+unicorn Launch Script

Asked 2 years ago, Updated 2 years ago, 168 views

Configuring Amazon Linux+unicorn+nginx+posgtresql (RDS) environment for Rails app production.

When writing unicorn startup scripts, I tried various information, but the startup failed.

Environment
ruby 2.2.2
rails 4.2.3
unicorn 4.9.0
postgresql9.2.13

Boot script /etc/init.d/unicorn contents

#!/bin/sh
#
#
# chkconfig:-8515
# description:unicorn--arrails app

. /etc/rc.d/init.d/functions

PROG_NAME=unicorn
USER=ec2-user
APP_ROOT=/home/ec2-user/server
RAILS_ENV=production
PID_FILE=$APP_ROOT/tmp/unicorn.pid
CONFIG_FILE = $APP_ROOT/config/unicorn.rb
CMD="/usr/local/rbenv/shims/unicorn_rails"
ARGS="-c$CONFIG_FILE-D-E$RAILS_ENV"

export PATH=/usr/local/bin:$PATH
cd$APP_ROOT||exit1

case $1 in
  start)
    daemon --user=$USER--pidfile=$PID_FILE$CMD$ARGS
    ;;
  stop)
    killproc-p$PID_FILE$PROG_NAME-QUIT
    ;;
  restart)
    killproc-p$PID_FILE$PROG_NAEE-USR2
    ;;
  *)
  echo>&2 "Usage: $0<start|stop|restart>"
  exit1
  ;;
esac

sudo service unicorn startThe error log during execution is as follows:

I, [2015-10-15T09:31:03.537055#17233] INFO --:reaped#<Process::Status:pid17236 exit 0>worker=0
I, [2015-10-15T09:31:03.537134#17233] INFO --:reaped#<Process::Status:pid17238 exit 0>worker=1
I, [2015-10-15T09:31:03.537193 #17233] INFO --: master complete
I, [2015-10-15T09:32:27.797578#17708] INFO --- Refreshing Gem list
I, [2015-10-15T09:32:29.038911#17708] INFO --:unlinking existing socket=/home/ec2-user/server/tmp/unicorn.sock
I, [2015-10-15T09:32:29.039043#17708] INFO --- listening on addr=/home/ec2-user/server/tmp/unicorn.sock fd=11
E, [2015-10-15T09:32:29.070183#17708] ERROR --:fe_sendauth:no password supported
 (PG:: ConnectionBad)

It says PG::ConnectionBad, so I think it's a problem with postgresql, but even if I look at various sites, it doesn't seem like unicorn is setting up anything about the database, so I don't know the reason for the error.In the production DB configuration of rails database.yml, the DB name, username, password (environment variable) and host configured in RDS are set, and the table can be created with the rakedb:migrate command.

ruby-on-rails nginx postgresql unicorn

2022-09-30 21:02

1 Answers

There is no environment to check, so I guess... I feel that unicorn is not starting correctly.
Perhaps the RAILS_ENV value is not set.

I think the cause is the unicorn_rails command.
This is, so to speak, a command for Rails 1 and 2.
Since Rails 3 has become a Rack application, try changing it to use the unicorn command.

https://stackoverflow.com/questions/12325923/what-is-the-difference-between-unicorn-and-unicorn-rails/12326124#12326124

http://unicorn.bogomips.org/unicorn_rails_1.html


2022-09-30 21:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.