linux启动java脚本

启动:

#!/bin/sh
psid=0

checkpid() {
   javaps=`jps -l | grep it.gotoandplay.smartfoxserver.GameServer`

   if [ -n "$javaps" ]; then
      psid=`echo $javaps | awk '{print $1}'`
   else
      psid=0
   fi
}

checkpid

if [ $psid -ne 0 ]; then
   echo "================================"
   echo "warn: server already started! (pid=$psid)"
   echo "================================"
else
   echo -n "Starting server ..."
   nohup java -Djava.ext.dirs=lib -Djava.library.path=lib it.gotoandplay.smartfoxserver.GameServer $* >/dev/null 2>&1 &
   checkpid
   if [ $psid -ne 0 ]; then
      echo "(pid=$psid) [OK]"
   else
      echo "[Failed]"
   fi
fi

 关闭:

#!/bin/sh
psid=0

checkpid() {
   javaps=`jps -l | grep it.gotoandplay.smartfoxserver.GameServer`

   if [ -n "$javaps" ]; then
      psid=`echo $javaps | awk '{print $1}'`
   else
      psid=0
   fi
}

checkpid

if [ $psid -ne 0 ]; then
   echo -n "Stopping server ...(pid=$psid) "
   kill -9 $psid
   if [ $? -eq 0 ]; then
      echo "[OK]"
   else
      echo "[Failed]"
   fi

   checkpid
   if [ $psid -ne 0 ]; then
      stop
   fi
else
   echo "================================"
   echo "warn: server is not running"
   echo "================================"
fi

 

你可能感兴趣的:(linux)