Pregunta

Tengo un proceso que se ejecuta como un demonio java en Ubuntu Linux.

No puedo detenerlo usando el comando start-stop-daemon en d_stop () a continuación.

El ID del proceso debe escribirse en el archivo $ PIDFILE durante el proceso de inicio, pero eso no funciona.

Aquí está mi 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 "."
¿Fue útil?

Solución

¿Hay alguna razón por la que no pueda usar start-stop-daemon para iniciar el proceso? Algo como esto debería ser lo que está buscando:

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

Si necesita establecer alguna variable de entorno, configúrelas en el script de inicio y expórtelas.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top