Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, Ive written a service script to run my java application which runs it using java command and the only way that i can stop the service is to kill ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2006
    Posts
    3

    A Service script question


    Hi,

    Ive written a service script to run my java application which runs it using java command and the only way that i can stop the service is to kill the java application using --> killall java, but since I may have other java apps running this command will kill all!
    Is there anyway I can kill the processes i started in start section of the script? since im a newbie in linux scripting any help would be appricieated!

    this is my current script -->

    <code>
    #!/bin/sh
    # Source function library.
    . /etc/init.d/functions
    RETVAL=$?
    case "$1" in
    start)
    echo $"Starting Sipop"
    /usr/local/jdk1.5.0_03/bin/java -classpath /usr/local/sipop:/usr/local/sipop/asterisk-java-0.2.jar net.translumina.sipop.SipopServer &
    ;;
    stop)
    killall java
    ;;
    *)
    echo $"Usage: $0 {start|stop}"
    exit 1
    ;;
    esac
    exit $RETVAL
    </code>

  2. #2
    Linux User muha's Avatar
    Join Date
    Jan 2006
    Posts
    290
    have you tried:
    top (afterwards press k to kill) OR
    ps aux (to see the pid)
    Now what? You have Linux installed and running. The GUI is working fine, but you are getting tired of changing your desktop themes. You keep seeing this "terminal" thing. Don't worry, they'll show you what to do @
    <~ http://www.linuxcommand.org/ ~>

  3. #3
    Just Joined!
    Join Date
    Apr 2006
    Posts
    3
    I want to stop that process using --> "service sipop stop" command automatically, Im looking for a way to save the pid in the service script so when it runs the "stop" function, the script can automatically find and kill that pid ..., im looking for such a script...

    OR is there any way I can change the process name of java in the start script after -->
    /usr/local/jdk1.5.0_03/bin/java -classpath /usr/local/sipop:/usr/local/sipop/asterisk-java-0.2.jar net.translumina.sipop.SipopServer &


    so i can run killall "the_new_name_of_the_process" in the stop script...

    Quote Originally Posted by muha
    have you tried:
    top (afterwards press k to kill) OR
    ps aux (to see the pid)

  4. $spacer_open
    $spacer_close
  5. #4
    Linux User
    Join Date
    Aug 2005
    Location
    Italy
    Posts
    401
    This is the solution: after your launch a process, the automatic variable $! contains the pid of the last command executed...

    So you'll start an application with:

    Code:
    java <program> && echo $! > /var/tmp/app.pid &
    So you'll stop the application with:

    Code:
    kill `cat /var/tmp/app.tmp`
    Enjoy!
    When using Windows, have you ever told "Ehi... do your business?"
    Linux user #396597 (http://counter.li.org)

  6. #5
    Just Joined!
    Join Date
    Apr 2006
    Posts
    3
    Thanks burnit, that script was what i exactly had been lookin for!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •