Ubuntu 18.04LTS
Jekyll 4.0.0
I’m running a PHP script to start a Jekyll server using a cronjob:
In the cronjob, I’m switching (from root) to the user who owns the local repo directory (ubuntu) then running the script. I’m switching user because the gems live in the user’s home directory.
The script works great when I run it from the command line as ubuntu, but not from the cronjob.
I’ve got Jekyll executing from cron, but there is a problem with Ruby being able to find the required gems.
I have added the path to my gems in ubuntu’s $PATH (/home/ubuntu/gems/gems) which is where ‘pathutil’ seems to live, and executing ‘gem list’ as the ubuntu user includes ‘pathutil (0.16.2)’
I verified that the script is running as ubuntu by echo’ing whoami.
(In the root cronjob, I’m actually running one script that requires root access then passing off (&&) to the ubuntu user script, and the root script is working great … it’s this second script that’s erroring.)
First, I’m posting the cronjob, then the script, then the error message.
I appreciate any guidance. Thank you in advance.
cronjob (runs every Saturday):
* * * * 5 sudo -u ubuntu /usr/bin/php /var/www/start_jekyll.php
start_jekyll.php:
$cmd = "/home/ubuntu/gems/gems/jekyll-4.0.0/exe/jekyll serve --verbose --trace";
chdir("/var/www/jekyll-site); # owned by ubuntu
$outputfile = "/var/www/jekyll-site/joutput";
$pidfile = "/var/www/jekyll-site/jpid";
exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile)); #silent
error (as seen in /var/www/jekyll-site/joutput):
/usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in 'require': cannot load such file -- pathutil (LoadError)
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in 'require'
from /home/ubuntu/gems/gems/jekyll-4.0.0/lib/jekyll.rb:32:in '<top (required)>'
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in 'require'
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in 'require'
from /home/ubuntu/gems/gems/jekyll-4.0.0/exe/jekyll:8:in '<main>'