将JAVA程序添加至系统服务

#!/bin/sh

### BEGIN INIT INFO
# Provides: java service
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start up the java service daemon.
# Description:       Start up the java service daemon.
### END INIT INFO

BASE_DIR="/home/yangxianchao/pq"
PID=$(ps -ef | grep com/st/pq/SendComments | awk '{if($3==1){print $2}}')

cd $BASE_DIR

start(){
  if [ "$PID" == "" ]
  then
    for i in *.jar
    do
      CLASS_PATH=$CLASS_PATH:$i
    done
    java -cp $CLASS_PATH com/st/pq/SendComments > /dev/null 2>&1 &
    sleep 1
    echo "Start."
  else
    echo "It's running."
  fi
}
stop(){
  if [ "$PID" == "" ]
  then
    echo "It's not running."
  else
    kill $PID
    sleep 1
    echo "Stop."
  fi
}
status(){
  if [ "$PID" == "" ]
  then
    echo "stop"
  else
    echo "running"
  fi
}
case $1 in
  start)
    start
  ;;
  stop)
    stop
  ;;
  status)
    status
  ;;
  *)
    echo "start|stop|status"
  ;;
esac

发表评论

电子邮件地址不会被公开。 必填项已用*标注