linux自定义服务

linux自定义服务

1.在/lib/systemd/system下新建一个文件,比如test.service,内容如下

[Unit]
Description=test.service #服务描述
Documentation=no #文档描述

[Service]
WorkingDirectory=/opt/test/ #工作目录
Type=forking #守护线程启动
ExecStart=/opt/test/test.sh  > /dev/null 2>&1 #启动脚本
ExecReload=/bin/kill -HUP $MAINPID # 重启,mainpid指向服务运行时的主进程号
KillMode=process # 关闭,杀死进程
Restart=on-failure #服务异常退出会重新启动
RestartSec=1s #重启等待时间


[Install]
WantedBy=multi-user.target graphic.target #表示多用户命令行状态

2.启动脚本test.sh

#!/usr/bin/env bash
rm -f /opt/test/tpid
export PATH=/usr/local/jdk/jdk1.8.0_91/bin:$PATH
nohup java -Xms4096m -Xmx4096m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./logs/heapdump-test.hprof -jar ./test.jar server  ./config/application.yml >/dev/null 2>&1 &
echo $! > /opt/test/tpid

3.服务启动

systemctl start test.service #服务注册启动

systemctl start test #启动
systemctl stop test #停止
mv /lib/systemd/system/test.service lib/systemd/system/test.service_bak 卸载
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值