jar包 制作为linux服务启动

1、vi /etc/rc.d/init.d/jwt(jwt为你要做服务的名字)

2.填写以下内容

#!/bin/bash
#chkconfig: 345 20 90
#description:jwt 1.0的服务
BASE_DIR="/soft/"
JAR_FILE="jwt.jar"
SERVICE_NAME="jwt1.0"
JAVA_PARAMS="-Xms256m -Xmx512m -XX:MaxNewSize=256m"
# JDK dir
JAVA_HOME=/home/staff/jdk1.8.0_161
PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
CLASSES=${CLASSPATH}:/usr/work/space1/bin
export JAVA_HOME
export PATH
export CLASSPATH
start()
{
echo "starting ${SERVICE_NAME}..."
nohup java $JAVA_PARAMS -jar $BASE_DIR$JAR_FILE -conf "$BASE_DIR"conf.json >>"$BASE_DIR"log.log &
echo "${SERVICE_NAME} started"
}

stop()
{
echo "stopping ${SERVICE_NAME}..."
pid=`ps -ef|grep $JAR_FILE |grep -v grep |awk '{print $2}'`
kill -9 $pid
echo "${SERVICE_NAME} stopped"
}

case "$1" in

start)
start
;;

stop)
stop
;;

restart)
stop
sleep 1
start
;;

*)

echo "Usage: $0 {start|stop|restart}"
exit 1
esac

 

 

3.赋予权限 chmod +x /etc/rc.d/init.d/jwt

4.添加开机启动  chkconfig --add jwt

 

chkconfig --del jwt
chkconfig --add jwt
chkconfig --list jwt

修改后需要先del 再 add

345 20 90才能保证网络服务已启动

5.启动服务     systemctl start jwt     或者  service jwt  start

你可能感兴趣的:(java)