0

I created a jar file store.jar and placed it inside: /etc/init.d directory ( I wanted to execute it on startup) I created a script test.sh (inside /etc/init.d) with following code:

java -jar store.jar

After that, I executed:

update-rc.d /etc/init.d/test.sh start 2

by following this thread:

How to run a script at the start up of Ubuntu?

If I execute the script from inside the /etc/init.d directory, it works fine.

/etc/init.d: sh test.sh

Problem 1.

If I'm on a different folder and run test.sh, it says unable to access store.jar

/home/abc: sh /etc/init.d/test.sh

Problem 2.

Nothing happened on ubuntu startup. I mean where can I see the reason why script did not run.

I hope you understand my question. Thanks

Community
  • 1
  • 1
Ashutosh
  • 4,371
  • 10
  • 59
  • 105

1 Answers1

0

Problem 1

Why don't you cd /etc/init.d/ before calling java -jar store.jar. That way, not matter where you are, it will find the store.jar file.

Problem 2

Less of an answer but why don't you pipe the output from executing the jar to a file. That will tell you if there are any issues in the jar. Furthermore, you could echo "This script ran" > ~/test.log to check if the script even ran at startup.

  • Hi mikeecb, thanks for the quick reply. Yes I'm able to run from inside /etc/init.d but I wanted to run by doing -classpath switch. I'll do the second one by piping the output. Thanks again – Ashutosh Aug 26 '15 at 13:18