I have a process that is running as a java daemon on Ubuntu Linux.
I cannot stop it using start-stop-daemon command in d_stop() below.
The process id should be written to file $PIDFILE during the start process, but that is not working.
Here is my script:
#! /bin/sh
#
#
#
# Version: @(#)daemon 1.0
#
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="xxxxx"
NAME="xxxxx"
USER="root"
HOME="/home/root"
MAIN="/opt/MYAPP/lib/NodeManager.jar"
APP_JAVAHOME="/home/owner/jdk1.6.0_17"
DAEMON="$APP_JAVAHOME/bin/java -server -Djava.awt.headless=true -jar $MAIN"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed.
test -x $APP_JAVAHOME/bin/java || exit 0
# ---------------------------------------
# Function that starts the daemon/service
# ---------------------------------------
d_start()
{
su -p -s /bin/sh - $USER -c "$DAEMON &> /dev/null & echo $!" > $PIDFILE
}
# --------------------------------------
# Function that stops the daemon/service
# --------------------------------------
d_stop()
{
start-stop-daemon --stop --quiet --pidfile $PIDFILE
#/bin/ps -ef | grep java | grep -v grep | awk '{print $2}
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."