我已经构建了一个监听webhook的node.js应用程序。目前,它用于构建jekyll网站。
我已经在服务器上配置了它,并且jekyll build
在jekyll网站(正在发送钩子)的根目录中运行它时,它可以完美运行。当我在外壳中的ssh上运行node.js应用程序时,当触发git钩子时,一切也都可以正常工作。
但是,当从新贵的脚本(如下所示)运行node.js应用程序时,似乎找不到该gems。它一直在询问我确定已安装的依赖项(全局以及针对我的用户)。
在我放入的脚本中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"
新贵的脚本来解决此问题,但这并没有改变任何内容。
同时,我已经通过手动将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
经过几个小时的痛苦,我终于解决了它。
诀窍是将设置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] 删除。
我来说两句