开机自动执行脚本文件

起因:seata单机部署需要通过 sh脚本启用,但是关机后,又得手动执行一遍,故,麻烦才有此脚本

创建 systemd 服务文件
cd /etc/systemd/system/

touch seata.service

vi /etc/systemd/system/seata.service
[Unit]
Description=Seata Server
After=network.target

[Service]
Type=simple
# 脚本实际路径,需替换为你的路径
ExecStart=/bin/sh /www/myserver/seata-bash/seata-server-1.4.2/bin/start.sh
# 可选:设置工作目录
WorkingDirectory=/www/myserver/seata-bash/seata-server-1.4.2/bin
# 可选:设置用户(若脚本需要特定权限)
User=root
# 保持服务运行(若脚本为后台运行模式)
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target
重载 systemd 配置并启用服务
# 重载配置
sudo systemctl daemon-reload
# 启用开机自启
sudo systemctl enable seata
# 立即手动启动服务
sudo systemctl start seata
验证服务状态
systemctl status seata.service
posted @ 2025-06-28 21:04  Y云间雾  阅读(44)  评论(0)    收藏  举报