7

I have a post-merge hook in my git repository that just runs the jekyll command.

When I run git pull, the post-merge runs with no problems.

However, I have setup a PHP file which will act as a WebHook for the remote:

$pull = `cd .. && git pull`;
echo $pull;

When I access this file, the git pull runs (after some initial problems) and is successful. However, for some reason the post-merge fails. If I look inside of my Apache error_log, I find the following error:

.git/hooks/post-merge: line 5: jekyll: command not found

This is odd, considering the post-merge successfully runs jekyll when I do a manual git pull via SSH.

If I run use the full path to the executable as suggested here, I get this error in my error_log:

/usr/bin/env: ruby_noexec_wrapper: No such file or directory

I installed Ruby through RVM.

How is it possible to have the apache user run jekyll with no problems?

Edit: Here is my current post-merge:

#!/bin/sh

unset GIT_DIR

source /usr/local/rvm/environments/ruby-1.9.3-p194

/usr/local/rvm/gems/ruby-1.9.3-p194/bin/jekyll

echo "Deployed!"

When I run this as the apache user, I now get this error:

Node.js is installed.

Community
  • 1
  • 1

3 Answers3

4

I think this error is very clear:

jekyll: command not found

you should use the complete path to your jekyll command.

whereis jekyll

then execute the command with the full path like:

/usr/local/bin/jekyll --params

Here is a solution for the ruby_noexec_wrapper problem.

/usr/bin/env ruby_noexec_wrapper fails with no file or directory

Edit:

Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available

ExecJS and could not find a JavaScript runtime

Community
  • 1
  • 1
René Höhle
  • 26,716
  • 22
  • 73
  • 82
  • After adding `source /usr/local/rvm/environments/ruby-1.9.3-p194` to my `post-merge` ([see here](http://hastebin.com/kocilaguva.bash)), I’m now getting [this error](http://hastebin.com/munuhurafu.vbs). I think it’s because jekyll has plugins which are requiring gems, and they would need sourcing too… right? –  Oct 24 '12 at 16:19
  • You should first look at the first error: Could not find a JavaScript runtimehttps://github.com/sstephenson/execjs the gem is missing. So you should follow this post: http://stackoverflow.com/questions/6282307/execjs-and-could-not-find-a-javascript-runtime – René Höhle Oct 24 '12 at 16:52
  • Hmm, if I run `jekyll` via SSH, I have no problems. I think I might have the gem, it’s just not got access? –  Oct 24 '12 at 16:53
  • I don't know what you do ;) but he can't find the JS runtime. Perhaps your path is wrong? Or your require not correct? Perhaps you run something what is not startet on with the SSH command? – René Höhle Oct 24 '12 at 16:56
  • http://stackoverflow.com/questions/7092107/rails-3-1-error-could-not-find-a-javascript-runtime everytime its the same. Install nodejs and test it again. – René Höhle Oct 24 '12 at 16:56
  • Then your gem is not working ;) there are not so much possibilities ;) then make a testscript and check the gem. – René Höhle Oct 24 '12 at 18:38
  • My gem works fine if I SSH and run `jekyll`, which suggests that the problem is because the WebHook, when run by user `apache`, does not have access to the gems. –  Oct 24 '12 at 19:48
  • And when you change to the apache user and test to run the command? su www-data -s /bin/bash or apache user. – René Höhle Nov 08 '12 at 14:43
  • There is your error: PERMISSION DENIED. Permission denied - /var/www/oliverash.me/site/2012/06/24/IMG_4411.html (Errno::EACCES) To fix this problem change the owner or group of this file or the folder to apache. – René Höhle Nov 08 '12 at 15:02
  • I fixed that, so I can now run `su apache -s /bin/bash; jekyll` and it works. However, when the WebHook is triggered, I’m still getting this error in my `error_log`: http://hastebin.com/jeyijawohi.vbs –  Nov 08 '12 at 16:05
  • I have made a chat-room: http://chat.stackoverflow.com/rooms/info/19335/git-webhook-php-cannot-access-ruby-environment?tab=general perhaps we can solve this problem. – René Höhle Nov 09 '12 at 10:22
  • The problem is we are in different time zones and countries i think. I am online now. – René Höhle Nov 14 '12 at 13:25
2

Because I was using RVM, I had to source that instead of Ruby directly. Not sure why, but it's working now.

My post-merge looks something like this:

#!/bin/bash

unset GIT_DIR

/usr/local/rvm/bin/rvm use 1.9.3

/usr/local/rvm/gems/ruby-1.9.3-p194/bin/jekyll

echo "Deployed!"

Not perfect – rvm echoes a load of stuff which I don't want, but it works.

0

I fixed this issue by adding the following to my ~/.bash_profile file:

source ~/.bashrc

The rvm installer should already have added

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

I added the source line above this and it fixed these issues.

M1ke
  • 6,166
  • 4
  • 32
  • 50