bash脚本无法识别Ruby宝石

克里斯托夫·德·特罗耶(Christophe De Troyer)

我已经构建了一个监听webhook的node.js应用程序。目前,它用于构建jekyll网站。

我已经在服务器上配置了它,并且jekyll build在jekyll网站(正在发送钩子)的根目录中运行它时,它可以完美运行。当我在外壳中的ssh上运行node.js应用程序时,当触发git钩子时,一切也都可以正常工作。

但是,当从新贵的脚本(如下所示)运行node.js应用程序时,似乎找不到该gems。它一直在询问我确定已安装的依赖项(全局以及针对我的用户)。

在我放入的脚本中echo`which jekyll`,这表明它确实指向本地安装的jekyllbin :/home/christophe/.gem/ruby/2.0.0/bin/jekyll但是在此之下,我执行jekyll命令,但它失败了:

/usr/lib/ruby/2.0.0/rubygems/dependency.rb:296:in `to_specs': Could not find 'jekyll' (>= 0) among 31 total gem(s) (Gem::LoadError)
    from /usr/lib/ruby/2.0.0/rubygems/dependency.rb:307:in `to_spec'
    from /usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_gem.rb:47:in `gem'
    from /home/christophe/.gem/ruby/2.0.0/bin/jekyll:22:in `<main>'

如何执行此bash脚本以正确执行jekyll?

暴发户

# /etc/init/libservice.conf
# Task to automatically start the library service.

author "Christophe De Troyer"
description "Run the githook for the blog."

# Path of the configuration files
env PROJ="/home/christophe/jekyll-builder"

# Configure to run as `christophe`
setuid christophe
setgid christophe

script
    export PATH=/home/christophe/.gem/ruby/2.0.0/bin:$PATH
    cd $PROJ
    gulp run
end script    

start on startup
#Respawn the process if it crashes
#If it respawns more than 10 times in 5 seconds stop
respawn limit 10 5

构建脚本

#!/bin/bash                                            

########################                               
# Parameters from Node #                               
########################                               

giturl=$1                                              
reponame=$2                                            
branch=$3                                              
ownermail=$4                                           
reporoot=$5                                            
htmlsink=$6                                            
www=$7                                                 

##########                                             
# Script #                                             
##########                                             

# Check to see if reponame exists. If not, git clone it
if [ ! -d $reporoot ]; then                            
    mkdir -p $reporoot                                 
    git clone $giturl $reporoot                        
fi                                                     

# Checkout and pull branch.                            
cd $reporoot                                           
git checkout $branch                                   
git pull origin $branch                                
cd -                                                   


echo `which jekyll` 
jekyll # fails                                   
# Run jekyll                                           
jekyll build -s $reporoot -d $htmlsink    # fails too

更新:

gem env 以用户身份登录时:

    RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.14
  - RUBY VERSION: 2.0.0 (2014-01-12 patchlevel 384) [x86_64-linux-gnu]
  - INSTALLATION DIRECTORY: /var/lib/gems/2.0.0
  - RUBY EXECUTABLE: /usr/bin/ruby2.0
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /var/lib/gems/2.0.0
     - /home/christophe/.gem/ruby/2.0.0
     - /usr/share/rubygems-integration/2.0.0
     - /usr/share/rubygems-integration/all
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/

gem env 从脚本中,通过upstart从运行的node.js应用程序执行,可以得到:

RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.14
  - RUBY VERSION: 2.0.0 (2014-01-12 patchlevel 384) [x86_64-linux-gnu]
  - INSTALLATION DIRECTORY: /var/lib/gems/2.0.0
  - RUBY EXECUTABLE: /usr/bin/ruby2.0
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /var/lib/gems/2.0.0
     - /.gem/ruby/2.0.0
     - /usr/share/rubygems-integration/2.0.0
     - /usr/share/rubygems-integration/all
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/

请注意,GEM_PATHS缺少第二个条目中的主目录前缀。我已经尝试通过放入env GEM_PATH="/home/christophe/.gem/ruby/2.0.0"新贵的脚本来解决此问题,但这并没有改变任何内容。

同时,我已经通过手动将deps列表作为root来解决了。但是,我认为这不是一个好方法,因为暴发户正以我的用户身份明确运行。其次,该软件需要在没有root权限的服务器上运行。所以我仍然想知道解决方法。

sudo gem install jekyll
sudo gem install jekyll-gist
sudo gem install jekyll-cite
sudo gem install jekyll-scholar
sudo gem install addressable -v 2.3.5
sudo gem install yajl-ruby -v 1.2.0
sudo gem install pygments.rb
sudo gem install posix-spawn
克里斯托夫·德·特罗耶(Christophe De Troyer)

经过几个小时的痛苦,我终于解决了它。

诀窍是将设置PATH为:/home/cdetroye/.rbenv/shims:/home/cdetroye/.rbenv/bin:/usr/local/bin:/usr/bin:/bin

# /etc/init/libservice.conf
# Task to automatically start the library service.

author "Christophe De Troyer"
description "Run the githook for the blog."

# Path of the configuration files

env PATH=/home/cdetroye/.rbenv/shims:/home/cdetroye/.rbenv/bin:/usr/local/bin:/usr/bin:/bin

# Configure to run as `christophe`
setuid cdetroye
setgid cdetroye

script
    cd $PROJ
    gulp run
end script    

start on startup
#Respawn the process if it crashes
#If it respawns more than 10 times in 5 seconds stop
respawn limit 10 5

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Bash 脚本无法识别文件

来自分类Dev

使用“ $ @”时脚本无法识别Bash“ -n”参数

来自分类Dev

为什么我的Bash脚本无法识别别名?

来自分类Dev

Bash脚本无法运行

来自分类Dev

Powershell脚本无法识别我的功能

来自分类Dev

Powershell脚本无法识别功能

来自分类Dev

Powershell脚本无法识别查询参数

来自分类Dev

外部脚本无法识别模型字段

来自分类Dev

Bash脚本无法将变量识别为路径的一部分

来自分类Dev

bash脚本无法使用rbenv和ruby build自动安装ruby

来自分类Dev

bash脚本无法使用rbenv和ruby build自动安装ruby

来自分类Dev

Bash脚本无法用作cronjob

来自分类Dev

Bash脚本无法从crontab正常运行

来自分类Dev

Bash脚本无法移动文件

来自分类Dev

Bash脚本无法找到Perl模块

来自分类Dev

bash脚本无法正常工作

来自分类Dev

Bash脚本无法正常工作

来自分类Dev

OSX bash脚本无法从cron运行

来自分类Dev

Bash 脚本无法在 Shell 中运行

来自分类Dev

Bash脚本无法执行bash脚本

来自分类Dev

脚本无法识别sudo密码并且失败

来自分类Dev

Google Apps脚本无法识别我的文档中的表格

来自分类Dev

PHP脚本无法识别电子邮件

来自分类Dev

验证脚本无法识别动态创建的表单

来自分类Dev

Shell脚本无法识别JAVA_HOME env变量

来自分类Dev

PHP脚本无法运行bash脚本。sh:权限被拒绝

来自分类Dev

Bash脚本无法正确调用其他脚本

来自分类Dev

Ruby无法识别Gemfile中包含的本地宝石

来自分类Dev

Bash脚本无法执行Go命令