Rails Byebug 权限 Errno::EACCES 使用脚本启动服务器时出错

Rails Byebug permission Errno::EACCES error while using script to start server

我读过几个类似的主题,其中建议 check/change 权限。我已经这样做了,但它不起作用。

这是我的项目文件夹权限:

$ stat trains
File: ‘trains’
Size: 4096          Blocks: 8          IO Block: 4096   directory
Device: 816h/2070d  Inode: 265254      Links: 14
Access: (0777/drwxrwxrwx)  Uid: ( 1000/   xxx)   Gid: ( 1000/   xxx)
Access: 2016-07-19 08:24:43.633340992 +0300
Modify: 2016-07-19 08:20:59.785332645 +0300
Change: 2016-07-19 08:24:43.533340989 +0300
Birth: -

我终端日志的最后几行:

  Errno::EACCES - Permission denied @ rb_sysopen - /.byebug_history:
  byebug (9.0.5) lib/byebug/history.rb:39:in `save'
  byebug (9.0.5) lib/byebug/interface.rb:110:in `autosave'
  byebug (9.0.5) lib/byebug/processors/command_processor.rb:121:in `after_repl'
  byebug (9.0.5) lib/byebug/processors/command_processor.rb:100:in `process_commands'
  byebug (9.0.5) lib/byebug/processors/command_processor.rb:56:in `at_line'
  byebug (9.0.5) lib/byebug/context.rb:96:in `at_line'
  app/controllers/stations_controller.rb:13:in `new'

我尝试用 777 权限自己创建 /.byebug_history 文件,但没用。

我检查过错误来自 .rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/byebug-9.0.5/lib/byebug/history.rb

从这部分开始(如果我评论它,错误就会消失)

  open(Setting[:histfile], 'w') do |file|
    n_cmds.times { file.puts(pop) }
  end

我已经检查了我的其他项目并从头开始创建了一个新项目,如果我尝试使用 byebug,它们都会抛出相同的错误。

更新

刚刚发现它与我用来启动服务器的 rails_server_helper 脚本有关。

这是脚本

function r() {
  if [ "" = "st" ]; then
     if [ "" = "" ]; then
        RENV="development"
     else
        RENV=""
     fi
     r sp
     rails server -d -e "$RENV"
     tail -f log/development.log
     return 0
  elif [ "" = "sp" ]; then
     if [ -f tmp/pids/server.pid ]; then
        kill  $(cat tmp/pids/server.pid)
        return 0
     else
        echo "It seems there is no server running or you are not in a rails project root directory"
        return 1
     fi
  elif [ "" = "rt" ]; then
     r sp && r st 
  else
 #    command rails $@
  echo "I don't know this command, dude..."
  fi;
}

它在 .bashrc 中像这样初始化:

if [ -f ~/@stuff/rails_server_helper.bash ]; then
    . ~/@stuff/rails_server_helper.bash
fi

因此,如果我不使用它并使用 rails server 命令正常启动 rails 服务器,那么 Byebug 权限错误就会消失,我会在应该出现的位置看到 Byebug 调试控制台。但是我不明白为什么。

好的,找到答案了。 原因是此脚本将 rails 服务器作为守护进程启动:

rails server -d

出于某种原因,调试在这种情况下不起作用。