Amiga 500
Amiga 500

Reputation: 15

Launch a Jar in Debian 7.9

i did a runnable jar and it goes good in my Debian, i want to autolanch it when my beaglebone board starts and kill it when it goes in shutdown. I tried with this file.sh inside the folder /etc/init.d

#!/bin/bash
### BEGIN INIT INFO
# Provides:          myscript.sh
# Required-Start:    $syslog
# Required-Stop:     $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: myscript.sh
### END INIT INFO
# MyApp
#
# description: It lanch the Jar file 

case $1 in
    start)
        /bin/bash /usr/local/bin/myapp-start.sh
    ;;
    stop)
        /bin/bash /usr/local/bin/myapp-stop.sh
    ;;
    restart)
        /bin/bash /usr/local/bin/myapp-stop.sh
        /bin/bash /usr/local/bin/myapp-start.sh
    ;;
esac
exit 0

I created also myapp-start.sh and stop in this way:

#!/bin/bash

/home/java -jar myjar.jar

and for the stop:

#!/bin/bash
# Grabs and kill a process 

pid=`ps aux | grep myapp | awk '{print $2}'`
kill -9 $pid

when i launch the update-rc.d myscript.sh defaults i received it: update-rc.d: using dependency based boot sequencing

What else i can do to solve it?

Upvotes: 2

Views: 170

Answers (1)

Stephen C
Stephen C

Reputation: 719561

I can see a couple of problems:

  1. You should NOT indent the #!/bin/bash line in any of your scripts. It will only work if the #! characters are the first two character of the file, etcetera. (The OS kernel decodes this line in a script file, and is is very picky.)

    The file also needs to have the appropriate execute bit set in the file's permissions; e.g. "ls -l myapp-start.s" needs to show an "x" for user, group or other.

  2. If you have the #! line correct, then you can run the script like this:

    /usr/local/bin/myapp-start.sh
    
  3. This is almost certainly incorrect:

     /home/java -jar myjar.jar
    

    Two problems:

    • Unless you've done something bizarre, /home/java is not the correct pathname for the java command.

    • You have specified the JAR filename using a relative path. It is unclear what the current directory will be if / when java is run, but it is unlikely that the myjar.jar file will be in the current directory.


A useful trick for debugging shell scripts like this is to add set -x or set -v to the script to see what it is doing. Please refer to man bash for details on what that does.

Upvotes: 1

Related Questions