在 Ubuntu 上启动 Unicorn 时权限被拒绝

在 Ubuntu 上启动 Unicorn 时权限被拒绝

我不熟悉 Ubuntu,并且我的 Rails 应用程序的服务器设置存在一些问题。

我在管理员组中创建了部署者用户 (%admin ALL=(ALL) ALL)。一切正常,但是当我尝试启动 Unicorn 服务时,收到权限被拒绝消息:

deployer@myvpsserver:~$ /etc/init.d/unicorn_myapp start
-bash: /etc/init.d/unicorn_myapp: Permission denied

这是我的/etc/init.d/unicorn_myapp:

!/bin/sh
### BEGIN INIT INFO
# Provides:          unicorn
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Manage unicorn server
# Description:       Start, stop, restart unicorn server for a specific application.
### END INIT INFO
set -e

# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/deployer/apps/myapp/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
AS_USER=deployer
set -u

OLD_PIN="$PID.oldbin"

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

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

run () {
  if [ "$(id -un)" = "$AS_USER" ]; then
    eval $1
  else
    su -c "$1" - $AS_USER
  fi
}

case "$1" in
start)
  sig 0 && echo >&2 "Already running" && exit 0
  run "$CMD"
  ;;
stop)
  sig QUIT && exit 0
  echo >&2 "Not running"
  ;;
force-stop)
  sig TERM && exit 0
  echo >&2 "Not running"
  ;;
restart|reload)
  sig HUP && echo reloaded OK && exit 0
  echo >&2 "Couldn't reload, starting '$CMD' instead"

ls -l /etc/init.d/unicorn_myapp 的结果

lrwxrwxrwx 1 root root 63 Aug  8 23:13 /etc/init.d/unicorn_myapp ->      
/home/deployer/apps/myapp/current/config/unicorn_init.sh

答案1

您可能需要sudo /etc/init.d/unicorn_myapp start,或者使用 在 init 脚本上设置可执行位chmod a+x /etc/init.d/unicorn_myapp。不过,这些都不是 Ubuntu 特有的东西。

相关内容