Question

I wrote init.d script that suppose to run java CLI proccess.
The problem is that when i stop it, i get [failed] and the proccess is still running.
thanks

#!/usr/bin/env bash
#
# chkconfig:    345 97 03
#
# processname:  quotes-srv
#
#
# source function library

. /etc/rc.d/init.d/functions

NAME=quotes-srv

start() {
    echo -n $"Starting $NAME: "
    daemon +19 java -Dlog4j.configuration="file:/opt/quotes/properties/log4j/log4j.properties"  -Dproperties_folder="/opt/quotes/properties/app/" -jar /opt/quotes/trade-0.0.1-SNAPSHOT-jar-with-dependencies.jar & 
touch /var/lock/subsys/$NAME
}

stop() {
    echo -n $"Stopping $NAME: "
    killproc $NAME
    echo
    rm -f /var/lock/subsys/$NAME
}

restart() {
    stop
    start
}

case "$1" in
  start)
    start
    ;;
  stop) 
    stop
    ;;
  restart|force-reload|reload)
    restart
    ;;
  condrestart|try-restart)
    [ -f /var/lock/subsys/$NAME ] && restart
    ;;
  status)
    status $NAME

    ;;
  *)
    echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
    exit 1
esac

exit 0
Was it helpful?

Solution

killproc will terminate programs in the process list which match the name $NAME

Strictly speaking this is in your case java .

If it is the only java process you can go and put java in $NAME

If you run other java services you have to find another way to stop your java process, e.g. putting the PID in the /var/lock/subsys/$NAME file and then killing the process using the pid.

On at least debian there is a nice tool which helps with this, but I am not sure it exists for redhat.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top