You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

RedHat服务器自定义systemd服务重启后无法被找到的问题求助

RedHat服务器自定义systemd服务重启后无法被找到的问题求助

我正在RedHat服务器上配置两个服务,分别负责开机启动数据库、关机停止数据库。我在/etc/systemd/system目录下创建了两个服务文件:

第一个是shutdown.service,内容如下:

[Unit]
Description=Shutdown database at shutdown
DefaultDependencies=no
Before=shutdown.target reboot.target halt.target

[Service]
Type=oneshot
ExecStart=/usr/DBA/shutdown.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

第二个是startup.service,内容如下:

[Unit]
Description=Start database at startup after network becomes reachable
After=default.target

[Service]
Type=simple
RemainAfterExit=yes
ExecStart=/usr/DBA/startup.sh
TimeoutStartSec=0

[Install]
WantedBy=default.target

之后我执行了这些命令:

sudo systemctl daemon-reload
sudo systemctl enable startup.service
sudo systemctl enable shutdown.service
sudo systemctl start startup.service
sudo systemctl start shutdown.service

执行完后查看状态,显示两个服务都正常运行(active and running)。但当我重启服务器后,再次查看服务状态时却出现了问题:

[ec2-user@ip-10-193-117-56 system]$ sudo systemctl status shutdown.service
Unit shutdown.service could not be found.

[ec2-user@ip-10-193-117-56 system]$ sudo systemctl status startup.service
Unit startup.service could not be found.

我完全搞不懂哪里出问题了——明明已经启用并启动了服务,按道理应该能自动运行,为什么重启后服务就找不到了呢?

另外,我确认服务文件确实还在目录里:

cd /etc/systemd/system
ls -l
-rw-rw-r--. 1 root root  246 Feb 22 16:02  startup.service
-rw-rw-r--. 1 root root  255 Feb 22 16:02  shutdown.service

有没有大佬能帮忙分析下原因?

备注:内容来源于stack exchange,提问作者Souad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 16:24:50