terça-feira, junho 15, 2004

Shell para iniciar um app java


Abaixo um pequeno shell para init.d / rc3.d / rc5.d para iniciar um programa em java, inclui start/stop
###############################################
#!/bin/sh
######## OPTIONALLY MODIFY THE VALUES OF THESE VARIABLES #########

#YOURPROGRAMHOME=//YourHome; export YOURPROGRAMHOME
#JAVA_HOME=/; export JAVA_HOME
#LD_LIBRARY_PATH=$YOURPROGRAMHOME/lib:$YOURPROGRAMHOME/bin; export LD_LIBRARY_PATH
#LIBPATH=$YOURPROGRAMHOME/lib:$YOURPROGRAMHOME/bin:/usr/lib:/lib; export LIBPATH
#CLASSPATH=$YOURPROGRAMHOME:.; export CLASSPATH
#MAINCLASS=java.util.String; export MAINCLASS
#PARAMS=; export PARAMS
#LOGFILE=app_log.log; export LOGFILE
#THISFILENAME=start.java; export THISFILENAME
###################################################################


killproc() { # kill the named process(es)

# get the script file pid from the "ps -ef" line, if there is one.
script_pid=`ps -ef | grep "$1" | grep -v grep | awk '{print $2}'`

if [ "$script_pid" != "" ]
then

# Get the child pid (if any); it's the associated java process
child_pid=`ps -ef | grep " $script_pid " | grep -v grep | grep -v "$1" | awk '{print $2}'`

# Kill the child process, if any, and the script process
# Note; must do child first or else it's "parent" may change
if [ "$child_pid" != "" ]
then
echo Stopping pid $child_pid
kill $child_pid 2> /dev/null
fi
echo Stopping pid $script_pid
kill $script_pid 2> /dev/null
fi
}


#
# Make sure this is not being run as root.
#
tmp_account=`id | cut -f2 -d\( | cut -f1 -d\)`

if [ "$tmp_account" = "root" ]
then
echo "* ERROR: This script should not be run as root."
exit 1
fi

#
# Make sure the needed environment variables are set.
#
if [ "$YOURPROGRAMHOME" = "" ]
then
echo ""
echo "** YOURPROGRAMHOME must be defined"
exit 1
elif [ "$JAVA_HOME" = "" ]
then
echo ""
echo "** JAVA_HOME must be defined"
exit 1
fi

#
# Determine platform.
#
PLATFORM=`uname -a | cut -f1 -d" "`; export PLATFORM

#
# Start your program
#


case "$1" in
'start')
echo "Starting the Application ..."
if [ "$PLATFORM" = "AIX" ]
then
java_options="-Djava.compiler=NONE"
else
java_options=""
fi
$JAVA_HOME/bin/java $java_options -Xms128m -Xmx128m -cp $CLASSPATH $MAINCLASS $PARAMS > $LOGFILE 2>&1
;;

#
# When the system is shutting down, stop the App
#

'stop')
echo "Stopping the Application ..."
killproc "$THISFILENAME start" 2> /dev/null
;;
*)
echo "Usage: $0 { start | stop }"
exit 1
;;
esac
exit 0
###############################################

Nenhum comentário: