1.创建服务
官网详细配置
vim /usr/lib/systemd/system/start-xxxx.service
# 主要是服务说明
[Unit]
# 服务说明
Description=开机启动脚本
# 本服务启动之前启动network服务
After=network.target
# 本服务启动之后启动xxxx服务
# Before=xxx.service
# 服务的关键
[Service]
# 表示后台运行模式
Type=forking
# 存放PID的绝对路径
PIDFile=/xxxx/xxx/jar.pid
# 服务启动命令,命令需要绝对路径
ExecStart=/xxxx/xxx/start-xxx.sh
# 重启命令,命令需要绝对路径
# ExecReload=xxx
# 停止命令,命令需要绝对路径
ExecStop=/xxxx/xxx/stop-xxx.sh
# 表示给服务分配独立的临时空间
PrivateTmp=true
# 定义 Systemd 停止当前服务之前等待的秒数
TimeoutSec=12000
[Install]
# 多用户
WantedBy=multi-user.target
2.开机自启动服务
centos7 常用服务操作命令
systemctl enable start-xxxx
本文介绍如何在 CentOS 7 中使用 Systemd 创建并配置服务,使其能够开机自启动。通过编辑 start-xxxx.service 文件,设置服务说明、依赖、类型、PID 文件、执行命令等关键参数。最后,通过 systemctlenable 命令启用服务。
2466

被折叠的 条评论
为什么被折叠?



