当前位置首页 > CentOS知识

centos7后台服务部署jar包

阅读次数:241 次  来源:admin  发布时间:

centos7 服务部署jar包 centos7 服务介绍

CentOS7的服务systemctl脚本存放在:/usr/lib/systemd/,有系统(system)和用户(user)之分,

每一个服务以.service结尾,一般会分为3部分:[Unit]、[Service]和[Install],具体内容如下:

[Unit]
Description=xiyoulibapi
After=network.target remote-fs.target nss-lookup.target
 
[Service]
Type=forking
PIDFile=/node.js/pid
ExecStart=/usr/local/bin/forever start /node.js/xiyoulib/bin/www
ExecReload=/usr/local/bin/forever restart /node.js/xiyoulib/bin/www
ExecStop=/usr/local/bin/forever stop /node.js/xiyoulib/bin/www
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

[Unit]部分主要是对这个服务的说明,内容包括Description和After,Description用于描述服务,After用于描述服务类别 [Service]部分是服务的关键,是服务的一些具体运行参数的设置,这里Type=forking是后台运行的形式,PIDFile为存放PID的文件路径,ExecStart为服务的具体运行命令,ExecReload为重启命令,ExecStop为停止命令,PrivateTmp=True表示给服务分配独立的临时空间,注意:[Service]部分的启动、重启、停止命令全部要求使用绝对路径,使用相对路径则会报错! [Install]部分是服务安装的相关设置,可设置为多用户的 jar包部署

[Unit]
Description=myapp service
After=syslog.target

[Service]
Type=simple
ExecStart=/usr/bin/java -Xms1024m -Xmx1024m -DSERVICE_LOG_FOLDER=/data/logs -jar /usr/local/software/myapp/myapp.jar --spring.config.location=/usr/local/software/myapp/bootstrap.yml
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
DSERVICE_LOG_FOLDER 日志输出目录 spring.config.location 初始配置文件 启动 systemctl start myapp 停止 systemctl stop myapp 重启 systemctl restart myapp 查看日志 journalctl -u myapp
上一篇:windowsServer----在iis上安装网站
下一篇:Fedora在招收新人方面又出新招;企业的开源之路等;开源之道每周评论(20191028)...