• Willkommen im Linux Club - dem deutschsprachigen Supportforum für GNU/Linux. Registriere dich kostenlos, um alle Inhalte zu sehen und Fragen zu stellen.

[solved] Sartscript für java Anwendungen

hi,
ich bin gerade etwas am verzweifeln.
ich versuche für eine java anwendung ein startscript zu basteln.
mein problem ist das programm checkproc.
ich kann damit nicht das richtige programm ermitteln da checkproc das erste programm nimmt was es findet. da java programme aber grundsätzlich mit java aufgerufen werden und wenn ich mehrere davon laufen habe ich immer ein und die selbe pid bekomme und damit zwangläufig auch die falsche.
hat jemand ne idee wie ich das checkproc beibiegen kann?

Ich hoffe ihr könnt halbwegs nachvollziehen was ich gerade suche ^^

Gruß & thx BB
 
hier das startscript was ich im jameica-Paket verwende.
Damit sollte dein Problem gelöst sein :)

Code:
#!/bin/sh

### BEGIN INIT INFO
# Provides:     jameica
# Required-Start:   $local_fs $remote_fs $network
# Required-Stop:    $local_fs $remote_fs $network
# Default-Start:    3 5
# Default-Stop:     0 1 2 6
# Short-Description:    Jameica Application Server
# Description:      Starts the Jameica Application Server
### END INIT INFO

# function javaps "shameless stolen" from
# Copyright (c) 2000 Alexander V. Konstantinou <akonstan@acm.org>
#
# Permission to use, copy, modify, distribute and sell this software
# and its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear
# in supporting documentation. Alexander V. Konstantinou makes no
# representations about the suitability of this software for any
# purpose.  It is provided "as is" without express or implied warranty.
# 
# Description: prints out the java processes running on a Linux host.
#              Optional "-noflags" argument controls verbosity
#
# Requirements: Linux host with a /proc filesystem
#
# Updates: http://www.cs.columbia.edu/~akonstan/javaps
function javaps()
{
	NOFLAGS=0
	if [ -n "$1" -a "$1" = "-noflags" ]; then
		NOFLAGS=1
	fi

	echo "PID	Process"

	# For every file in the /proc file system
	FILES=`/bin/ls -1 /proc`

	for FILE in $FILES; do
		PROCESS_ID=$FILE
  		STATUS_FILE=/proc/$FILE/status
  		CMDLINE_FILE=/proc/$FILE/cmdline

  		# Check if it is a process directory and that we have read access
  		if [ -d "/proc/$FILE" -a -r $STATUS_FILE -a -r $CMDLINE_FILE -a "$FILE" != "/proc/self" ]; then
			PROCESS_NAME=`grep 'Name:' $STATUS_FILE | awk '{print $2}'`

    		# Only interested in java processes
    		if [ "$PROCESS_NAME" = "java" ]; then
      			PARENT_PID=`grep 'PPid' $STATUS_FILE | awk '{print $2}'`

      			# Figure out if process has a parent that is a java process
      			ISROOT=0
      			if [ $PARENT_PID -eq 1 ]; then
        			ISROOT=1
      			else
        			PARENT_NAME=`grep 'Name:' /proc/$PARENT_PID/status | awk '{print $2}'`
        			if [ "$PARENT_NAME" != "java" ]; then
          				ISROOT=1
        			fi
      			fi

      			# If root java process print out
      			if [ $ISROOT -ne 0 ]; then
        			PROCESS_CMDLINE="`cat $CMDLINE_FILE | tr '\000' ' '`"
					IGNORE_ARG=0
        			DESCR=
        			for ARG in $PROCESS_CMDLINE; do
          				if [ $NOFLAGS -eq 0 ]; then
             				DESCR="$DESCR $ARG"
          				else
            				if [ $IGNORE_ARG -eq 0 ]; then
              					if [ $ARG = "-classpath" -o $ARG = "-cp" ]; then
                					IGNORE_ARG=1
              					elif [ -z "`echo $ARG | grep '^-D'`" -a -z "`echo $ARG | grep '^-X'`" ]; then
                					DESCR="$DESCR $ARG"
              					fi
            					else 
             						IGNORE_ARG=0
            				fi
          				fi
        			done
        			echo "$PROCESS_ID	$DESCR"
      			fi
    		fi
  		fi
	done
}


#
# Determine the base and follow a runlevel link name.
#
base=${0##*/}
link=${base#*[SK][0-9][0-9]}

#JAVA=`which java`
#BASEDIR=`dirname $0`
WORKDIR=~/.jameica
PASSWORD=CHANGE_THIS_BEFORE_YOU_START_JAMEICA
PIDFILE=$WORKDIR/jameica.pid

### Please do not edit anything below this line! ########################
#                                                                       #

. /etc/rc.status

rc_reset

return=$rc_done
case "$1" in
	start)
		mkdir -p $WORKDIR
		echo -n "Starting Jameica "
		/usr/bin/jameicaserver.sh -n -f $WORKDIR -p $PASSWORD > /dev/null 2>&1 &
		sleep 1
		PID=`javaps -noflags | grep jameica | awk '{print $1}'`
#		echo "jameica started with PID=$PID"
		rc_status -v
		echo $PID > $PIDFILE
		;;
	stop)
		if test -e $PIDFILE ; then
			echo -n "Shutting down Jameica "
			kill `cat $PIDFILE`
			rm -f $PIDFILE
			rc_status -v
		else
			echo "Not running"
		fi
		;;
	reload|restart)
		$0 stop
		sleep 1
		$0 start
		;;
	status)
		echo -n "Checking for Jameica "
		if test -e $PIDFILE ; then
			echo " seems running"
		else
			echo " not running"
		fi
		;;
	*)
		echo "Usage: $0 {start|stop|restart|status}"
		exit 1
		;;
esac
rc_exit
 
Oben