现在Spring等框架可以支持别用War发布而是用Jar发布,这样服务器就不用安装容器了,方便不少。但不安装容器就需要自己来写脚本完成服务的启动、停止、重启。
脚本如下:
#!/bin/bash # # chkconfig: 345 70 30 # description: ${description} # processname: ${processName} # Source function library. #!/bin/sh SERVICE_NAME=${serviceName} PATH_TO_JAR=${jarFile} PID_PATH_NAME=/tmp/${serviceName}-pid case $1 in start) echo "Starting $SERVICE_NAME ..." if [ ! -f $PID_PATH_NAME ]; then nohup java -jar ${javaArgs} $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null & echo $! > $PID_PATH_NAME echo "$SERVICE_NAME started ..." else echo "$SERVICE_NAME is already running ..." fi ;; stop) if [ -f $PID_PATH_NAME ]; then PID=$(cat $PID_PATH_NAME); echo "$SERVICE_NAME stoping ..." kill $PID; echo "$SERVICE_NAME stopped ..." rm $PID_PATH_NAME else echo "$SERVICE_NAME is not running ..." fi ;; restart) if [ -f $PID_PATH_NAME ]; then PID=$(cat $PID_PATH_NAME); echo "$SERVICE_NAME stopping ..."; kill $PID; echo "$SERVICE_NAME stopped ..."; rm $PID_PATH_NAME echo "$SERVICE_NAME starting ..." nohup java -jar ${javaArgs} $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null & echo $! > $PID_PATH_NAME echo "$SERVICE_NAME started ..." else echo "$SERVICE_NAME is not running ..." fi ;; esac
时间: 2024-12-15 04:57:34