博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
systemd自启动java程序
阅读量:7245 次
发布时间:2019-06-29

本文共 1052 字,大约阅读时间需要 3 分钟。

一、背景条件

1. Linux系统是Debian 8

2. Java程序是test.jar,安装路径是/home/test/test.jar

二、编写java的启动脚本

startTest.sh

#!/bin/shjava -jar /home/test/test.jar &echo $! > /var/run/test.pid

三、编写java的停止脚本

stopTest.sh

#/bin/shPID=$(cat /var/run/test.pid)kill -9 $PIDrm -fr /var/run/test.pid

四、编写testJava.service

[Unit]Description=TestJavaAfter=network.target[Service]Type=forkingExecStart=/home/test/startTest.shExecStop=/home/test/stopTest.sh[Install]WantedBy=multi-user.target

五、添加到自启动

systemctl enable testJava

六、测试

启动: systemctl start testJava

停止: systemctl stop testJava

附、tomcat自启动service的配置

[Unit]Description=TomcatAfter=network.target[Service]Type=forkingPIDFile=/usr/local/apache-tomcat-8.5.20/tomcat.pidExecStart=/usr/local/apache-tomcat-8.5.20/bin/catalina.sh startExecReload=/usr/local/apache-tomcat-8.5.20/bin/catalina.sh restartExecStop=/usr/local/apache-tomcat-8.5.20/bin/catalina.sh stop[Install]WantedBy=multi-user.target

1. 需要在catalina.sh中添加CATALINA_PID的参数配置和PID一致。

2. tomcat.service文件放置路径 /lib/systemd/system/

 

转载于:https://www.cnblogs.com/yoyotl/p/8178363.html

你可能感兴趣的文章
php总结二篇
查看>>
vue 开发系列(七) 路由配置
查看>>
英特尔® 图形性能分析器 2019 R1 版本
查看>>
Developing avb
查看>>
Virtualbox中的Linux:未能加载虚拟光驱 VBoxsGuestAdditions.iso到虚拟电脑
查看>>
linux 本地账号密码无法登陆(shell可以登录),一直返回 登陆的login界面
查看>>
使用oracle来计算方差及标准差
查看>>
ORACLE备份、恢复、常用查询
查看>>
矩阵翻硬币 蓝桥杯
查看>>
启动和停止数据库——启动例程并打开数据库
查看>>
模板模式讲解二
查看>>
core.async中go的作用研究
查看>>
除法(暴力)
查看>>
Python tornado初探
查看>>
metro 文本文件操作
查看>>
【第46题】【062题库】2019年OCP认证062考试新题
查看>>
1297 硬币
查看>>
ORA-01665 control file is not a standby control file
查看>>
pycharm 文件名不显示中文的解决方法
查看>>
340 - Master-Mind Hints
查看>>