Domanda

Ho un processo in esecuzione come demone Java su Ubuntu Linux.

Non riesco a fermarlo usando il comando start-stop-daemon in d_stop () di seguito.

L'ID processo deve essere scritto nel file $ PIDFILE durante il processo di avvio, ma che non funziona.

Ecco il mio 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 "."
È stato utile?

Soluzione

C'è qualche motivo per cui non puoi usare start-stop-daemon per avviare il processo - qualcosa del genere dovrebbe essere quello che stai cercando:

DAEMON="$APP_JAVAHOME/bin/java"
ARGS="-server -Djava.awt.headless=true -jar $MAIN"

start-stop-daemon --start --pidfile "$PIDFILE" --chuid "$USER" --background --make-pidfile --startas "$DAEMON" -- $ARGS

Se sono necessarie variabili di ambiente impostate, impostarle nello script di avvio ed esportarle.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top