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.
/test/run.sh
#!/bin/bash
java -cp myjar:/test/lib/* com.xxxx.util.AmazonS3FileDownloader
I have also created a file called test
in /etc/init.d
/etc/init.d/test
#!/bin/bash
/test/run.sh
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.
cwd
? If the script is creating the file atcwd
, then you have tocd /test
before running the script.