I have a script that execute a java program, and I want to create a service to start this script at boot time.

So I've created a script called run.sh.


java -cp myjar:/test/lib/* com.xxxx.util.AmazonS3FileDownloader

I have also created a file called test in /etc/init.d



For testing purposes I gave the test folder /test all rights (chmod 777 /test).

drwxrwxrwx    7 testuser testuser  4096 Dec 12 13:28 test

And this is what inside /etc/ini.d folder

-rwxr-xr-x  1 root root  2062 Dec 12 13:18 test

If I run this command. Everything is fine. No error, the program is running fine.

$ /test/run.sh

but for a reason I ignore if I try to do the same thing but using the service. It doesn;t work.

$ service test start

I've got permission denied when creating the receipts_download.log in /test folder.

log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: receipts_download.log (Permission denied)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:142)
    at org.apache.log4j.FileAppender.setFile(FileAppender.java:290)
    at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:194)
    at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:164)
    at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:257)
    at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:133)
    at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:97)
    at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:689)
    at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:647)
    at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:544)
    at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:440)
    at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:476)
    at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:471)
    at org.apache.log4j.LogManager.<clinit>(LogManager.java:125)
    at org.apache.log4j.Logger.getLogger(Logger.java:118)
    at com.xxxxx.util.AmazonS3FileDownloader.<init>(Unknown Source)
    at com.xxxxx.util.AmazonS3FileDownloader.main(Unknown Source)

/test has all permission and why I can run $ /test/run.sh without problem but not $ service test start

Thanks for your help.

  • Is it hard-coded in the script to create the file in '/test' directory? Or the script is creating the file at cwd ? If the script is creating the file at cwd, then you have to cd /test before running the script.
    – Sreeraj
    Commented Dec 12, 2014 at 14:37
  • @Sree instead of doing /test/run.sh in the test script, I did cd /test and then ./run.sh and it seems to work fine. Thanks a lot. If you want you response accepted you can write one and I will accept it ;)
    – TheEwook
    Commented Dec 12, 2014 at 14:56
  • re-wrote it in the answer section. Thanks.
    – Sreeraj
    Commented Dec 12, 2014 at 14:59

2 Answers 2


It looks like the script is creating the 'receipts_download.log' file in the cwd and your cwd when running the script is not /test. Please cd /test before running the script and it will go okay.


The difference is most likely in environment variables and current working directory. service starts script from / and with clean environment. So, you may need to examine your environment and current working directory (with the help of export, pwd or set commands) and add missing prerequisites into your script.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .