SUSE self-starting java program at boot

I want to make a script that can automatically start our company's program on boot in SUSE system. I've searched a lot, and now I've been able to start it automatically. But whether this program has problems in actual use has not been tested.

The following is through

The method of chkconfig service_name on is used.

The first step: generate a service_name (whatever the service is called) script, in the directory /etc/rc.d/. The content of the script is as follows:

#!/bin/sh
#runserver.sh
#--------------------------------------- ----------------------------
# Self-start the ICBCMISSERVER service under SUSE system. It is mainly used for Harbin New World
# without considering the prerequisites for starting the service and the conditions for stopping the service.
#------------------------------------------------- ------------------
### BEGIN INIT INFO
# Provides: MisServer
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Description: Start the MisServer Damon
### END INIT INFO


CURRENT_DIR=/opt/misserver
MISSERVER_HOME=$CURRENT_DIR
JAVA_HOME=/opt/jdk1.5.0_06
JAVA_OPTS="-Dcom.peakvision.pvds.home=$MISSERVER_HOME"
JAVA_OPTSLOG4J="-Dlog4j.configuration=log4j.properties"
#MisServer服务
MIS_LOG4J="-Dlog4j.configuration=log4jMisServer.properties"
_RUNJAVA="$JAVA_HOME"/bin/java

if [ -z "$CLASSPATH" ]; then
 CLASSPATH="$MISSERVER_HOME"/plugin:"$MISSERVER_HOME"/conf
else
 CLASSPATH="$CLASSPATH":"$MISSERVER_HOME"/plugin:"$MISSERVER_HOME"/conf
fi
for i in "$MISSERVER_HOME"/lib/*.jar; do
 CLASSPATH="$CLASSPATH":"$i"
done


case "$1" in
 "start"  ) 
  echo '启动MisServer.'
  "$_RUNJAVA" "$JAVA_OPTS" "$MIS_LOG4J" -classpath "$CLASSPATH" -Xms32m -Xmx256m com.peakvision.pvds.server.misserver.MisServer &
 ;;
  
 "stop"  )
  echo '关闭MisServer.'
  "$_RUNJAVA" "$JAVA_OPTS" "$MIS_LOG4J" -classpath "$CLASSPATH" -Xms32m -Xmx256m com.peakvision.pvds.server.misserver.ShutdownMisServer &
 ;;
    
 * )
  exit 1 ;;
esac

 

Step 2:

chkconfig service_name on

In this way, the java program can be registered and used in the system as a service. with the command:

chkconfig  --list serivce_name

You can see which RUNLEVEL this service is started under.

-------------------------------------------------- ---------------Finish---------------------------------- --------------------------

If you want to test it, you can use this command to see if the program can be started without restarting.

service service_name start

------------------------------------------potential problem---- -------------------------------------------------- ---------------

1. After booting, use the command ps -ef|grep service_name to query the service process information, which will add this line to the normal startup:

root      2080     1  0 23:21 ?        00:00:00 startpar -f -- service_name

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326426399&siteId=291194637