学盟网是一个互助、分享,一起学习和成长的公益平台,学盟网,有你更精彩!按Ctrl+D收藏学盟网!
当前位置:首页 > 电脑 > linux → Linux系统下的Java进程不见了怎么办

Linux系统下的Java进程不见了怎么办

时间:2016-11-30 16:21:12 作者:andy 来源:linux 阅读:

很多用户表示,Linux系统下的一些Java项目总是会无缘无故的消失,Linux系统下的Java进程不见了怎么办呢?今天小编就和大家说说Linux系统下的Java进程不见了的解决方法。

64-160225161354551.jpg

Linux系统下的Java进程不见了解决方法

1.磁盘满了,这个问题比较简单,只要清理一下磁盘就可以了。

2.tomcat在关闭的或是重启的时候,常常后台进程没有被关闭。需要用ps aux|grep java 这个命令查一下,把多余的进程关掉,再启动startup.sh

3.这种情况比较少见,就是在系统资源缺少的情况下,被系统自动DOWN掉,或是被其它软件干掉了。

其实在我这里,这样还是没有解决,进程还是莫名其妙会自己挂掉,日志也没有任何报错。后来打开tomcat主目录下的子目录conf里面的tomcat-users.xml文件,用户配置内容如下:

全都关闭掉。

linux下启动java程序的通用脚本介绍

一、start.sh

#!/bin/bash

cd `dirname $0`

BIN_DIR=`pwd`

cd ..

DEPLOY_DIR=`pwd`

CONF_DIR=$DEPLOY_DIR/conf

SERVER_NAME=`sed '/server.name/!d;s/.*=//' conf/server.properties | tr -d '\r'`

SERVER_PORT=`sed '/server.netty.port/!d;s/.*=//' conf/server.properties | tr -d '\r'`

if [ -z "$SERVER_NAME" ]; then

SERVER_NAME=`hostname`

fi

PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`

if [ -n "$PIDS" ]; then

echo "ERROR: The $SERVER_NAME already started!"

echo "PID: $PIDS"

exit 1

fi

if [ -n "$SERVER_PORT" ]; then

SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l`

if [ $SERVER_PORT_COUNT -gt 0 ]; then

echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!"

exit 1

fi

fi

LOGS_DIR=""

LOGS_DIR=$DEPLOY_DIR/logs

#if [ ! -d $LOGS_DIR ]; then

# mkdir $LOGS_DIR

#fi

STDOUT_FILE=$LOGS_DIR/stdout.log

LIB_DIR=$DEPLOY_DIR/lib

LIB_JARS=`find $LIB_DIR|grep .jar|awk '{print $0}'|tr "\n" ":"`

JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "

JAVA_DEBUG_OPTS=""

if [ "$1" = "debug" ]; then

JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n "

fi

JAVA_JMX_OPTS=""

if [ "$1" = "jmx" ]; then

JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false "

fi

JAVA_MEM_OPTS=""

BITS=`file $JAVA_HOME/bin/java | grep 64-bit`

if [ -n "$BITS" ]; then

let memTotal=`cat /proc/meminfo |grep MemTotal|awk '{printf "%d", $2/1024 }'`

if [ $memTotal -gt 2500 ];then

JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -Xmn400m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "

else

JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -Xmn400m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "

fi

else

JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC "

fi

echo -e "Starting the $SERVER_NAME ...\c"

nohup java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS -classpath $CONF_DIR:$LIB_JARS com.hzins.framework.server.ServerMain > $STDOUT_FILE 2>&1 &

COUNT=0

while [ $COUNT -lt 1 ]; do

echo -e ".\c"

sleep 1

# if [ -n "$SERVER_PORT" ]; then

# COUNT=`echo status | nc 127.0.0.1 $SERVER_PORT -i 1 | grep -c OK`

# else

COUNT=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print $2}' | wc -l`

# fi

if [ $COUNT -gt 0 ]; then

break

fi

done

echo "OK!"

PIDS=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print $2}'`

echo "PID: $PIDS"

#echo "STDOUT: $STDOUT_FILE"

二、stop.sh

#!/bin/bash

cd `dirname $0`

BIN_DIR=`pwd`

cd ..

DEPLOY_DIR=`pwd`

CONF_DIR=$DEPLOY_DIR/conf

SERVER_NAME=`sed '/server.name/!d;s/.*=//' conf/server.properties | tr -d '\r'`

if [ -z "$SERVER_NAME" ]; then

SERVER_NAME=`hostname`

fi

PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`

if [ -z "$PIDS" ]; then

echo "ERROR: The $SERVER_NAME does not started!"

exit 1

fi

if [ "$1" != "skip" ]; then

$BIN_DIR/dump.sh

fi

echo -e "Stopping the $SERVER_NAME ...\c"

for PID in $PIDS ; do

kill $PID > /dev/null 2>&1

done

COUNT=0

while [ $COUNT -lt 1 ]; do

echo -e ".\c"

sleep 1

COUNT=1

for PID in $PIDS ; do

PID_EXIST=`ps --no-heading -p $PID`

if [ -n "$PID_EXIST" ]; then

COUNT=0

break

fi

done

done

echo "OK!"

echo "PID: $PIDS"

三、restart.sh

#!/bin/bash

cd `dirname $0`

./stop.sh

./start.sh

123

文章目录

CopyRight © 2011-2016 学盟网 www.xuenb.com All Rights Reserved.

'); })();