【问题标题】:Syntax error near unexpected token `(' on service unicorn start on amazon EC2 linux亚马逊 EC2 linux 上的服务独角兽启动上的意外令牌“(”附近的语法错误
【发布时间】:2015-08-29 07:56:54
【问题描述】:

我正在尝试在 Amazon EC2 中设置 Unicorn。我正在关注this blog

但是当我使用 Unicorn 启动时:

sudo service unicorn_firstapp start

我收到以下错误:

/home/ec2-user/rails_projects/firstapp/config/unicorn.rb: line 2: syntax error near unexpected token `('
/home/ec2-user/rails_projects/firstapp/config/unicorn.rb: line 2: `app_dir = File.expand_path("../..", __FILE__)'

我的错误是什么?如果有人对此问题有任何想法,请与我分享。

unicorn.rb:

# 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 "#{shared_dir}/sockets/unicorn.sock", :backlog => 64

# 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"

/etc/init.d/unicorn_firstapp:

#!/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="ec2-user"
APP_NAME="firstapp"
APP_ROOT="/home/$USER/rails_projects/$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"

#setting for RVM
RAILS_ENV=production
PID=$APP_ROOT/shared/pids/unicorn.pid
DESC="Unicorn app - $RAILS_ENV"
UNICORN="$APP_ROOT/config/unicorn.rb"
UNICORN_OPTS="-c $APP_ROOT/config/unicorn.rb -E $RAILS_ENV -D"
CMD="RAILS_ENV=$RAILS_ENV $UNICORN $UNICORN_OPTS"
TIMEOUT=60


# make sure the app exists
cd $APP_ROOT || exit 1

sig () {
  test -s "$PID" && kill -$1 `cat $PID`
}

oldsig () {
  test -s $OLD_PID && kill -$1 `cat $OLD_PID`
}

case $1 in
  start)
    sig 0 && echo >&2 "Already running" && exit 0
    echo "Starting $APP_NAME"
    su - $USER -c "$CMD"
    ;;
  stop)
    echo "Stopping $APP_NAME"
    sig QUIT && exit 0
    echo >&2 "Not running"
    ;;
  force-stop)
    echo "Force stopping $APP_NAME"
    sig TERM && exit 0
    echo >&2 "Not running"
    ;;
  restart|reload|upgrade)
    sig USR2 && echo "reloaded $APP_NAME" && exit 0
    echo >&2 "Couldn't reload, starting '$CMD' instead"
    $CMD
    ;;
  rotate)
    sig USR1 && echo rotated logs OK && exit 0
    echo >&2 "Couldn't rotate logs" && exit 1
    ;;
  *)
    echo >&2 $USAGE
    exit 1
    ;;
esac

【问题讨论】:

    标签: ruby-on-rails linux nginx amazon-ec2 unicorn


    【解决方案1】:

    尝试包含正确的 hash-bang 标头,否则您的代码将使用您的 shell 执行:

    #!/usr/bin/env ruby
    
    app_dir = File.expand_path("../..", __FILE__)
    ...
    

    希望对您有所帮助。

    【讨论】:

    • 感谢您的回复,但现在收到此错误。 main:Object (NoMethodError) 的未定义方法“working_directory”
    猜你喜欢
    • 2021-02-03
    • 2014-11-27
    • 2018-11-01
    • 2014-03-25
    • 1970-01-01
    • 2019-02-24
    • 2023-04-01
    • 2017-11-19
    • 2021-06-13
    相关资源
    最近更新 更多