首页 > 代码库 > 在Linux上讲Java命令行的作为服务运行
在Linux上讲Java命令行的作为服务运行
现在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
在Linux上讲Java命令行的作为服务运行
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。