How can I give mkdir permissions to a script that is called by sudo systemctl start <service-name> ??

Here is the error being thrown in the results of sudo journalctl -u jekyll -f when I type the sudo systemctl start jekyll command:

Mar 20 18:29:52 long.host.name jekyll[5280]: /usr/share/ruby/fileutils.rb:239:in `mkdir': Permission denied @ dir_s_mkdir - /.jekyll-cache (Errno::EACCES)

I then opened /usr/share/ruby/fileutils.rb and saw that the directories to be created were in the /usr/local/lib/ruby path. Since /usr/local/lib/ already existed, I typed the following two commands to remove all obstacles to anyone writing to these directories:

sudo chown -R jekyll-host:jekyll-host /usr/local/lib  
sudo chmod 777 /usr/local/lib  

And then I also separately upgraded to root with sudo su - and I ran the systemctl start jekyll command as root, but even this resulted in the same permissions error shown above.

The line in the jekyll.service file that attempts to start this server but throws the above error is:

ExecStart=/bin/sh -c '/usr/local/bin/jekyll s --trace' 

As you can surmise, the /usr/local/bin/jekyll program called in the ExecStart command in turn calls other scripts including the /usr/share/ruby/fileutils.rb script shown above which does not seem to have permissions to create a directory.

This is running on an EC2 instance with Amazon Linux 2, which of course is an extension of RHEL.

What specific syntax needs to be changed in order to adequate permissions to be propagated throughout the chain of programs that are called when this sudo systemctl start jekyll command is run?


Your program is trying to create a directory in the root of the filesystem. This is not a permissions problem, and it would be very daft indeed to "solve" it by granting any write rights to the root directory.

This is a configuration problem, of some kind, either in your service's own configuration or in the systemd service unit. Find out why your service incorrectly thinks that the root directory is the place to create its cache directory. Fix that.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.