![暴发户](https://linux22.com/image/81012/%E6%9A%B4%E5%8F%91%E6%88%B7.png)
我构建了一个监听 webhook 的 node.js 应用程序。目前它用于构建jekyll网站。
我已经在我的服务器上配置了它,并且jekyll build
当我在 jekyll 网站的根目录(正在发送钩子)中运行它时,它可以完美地工作。当我在 shell 中通过 ssh 运行 node.js 应用程序时,当触发 git hook 时,一切都工作正常。
然而,当 Node.js 应用程序从一个新贵脚本运行时(如下所示),它似乎找不到 gem。它不断询问我确信我已经安装的依赖项(全局以及我的用户)。
在我放入的脚本中echo`which jekyll`
,这表明它确实指向本地安装的jekyll
bin: /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"
新贵脚本来解决这个问题,但这并没有改变任何东西。
与此同时,我通过以 root 身份手动安装 deps 列表来解决这个问题。但是,我认为这不是一个好方法,因为暴发户明确以我的用户身份运行。其次,这个软件需要在我没有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
答案1
你尝试过设置GEM_HOME
环境吗?我至少能够通过以下方式获得列出自定义安装目录的新贵服务:
cd
gem install rake --install-dir grepable
然后使用/etc/init/footest.conf
以下服务:
author "Nobody"
description "Echo some details"
env GEM_HOME="/home/jdoe/grepable"
setuid jdoe
setgid jdoe
script
/usr/bin/gem environment
end script
start on startup
respawn limit 10 5
重新启动后,
# fgrep -1 grep /var/log/upstart/footest.log
- RUBY VERSION: 1.9.3 (2013-11-22 patchlevel 484) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/jdoe/grepable
- RUBY EXECUTABLE: /usr/bin/ruby1.9.1
- EXECUTABLE DIRECTORY: /home/jdoe/grepable/bin
- RUBYGEMS PLATFORMS:
--
- GEM PATHS:
- /home/jdoe/grepable
- /.gem/ruby/1.9.1
对于生产服务,人们可能会在不适合供应商空间或主目录的地方使用--install-dir
/ 。GEM_HOME
答案2
经过几个小时的痛苦,我终于修好了。
诀窍是将 设为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