我正在尝试在 Redhat 服务器中设置 2 个在启动时启动数据库并在关闭时停止的服务,因此我将 2 个文件放在如下位置/etc/systemd/system
:
关机服务:
[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
启动服务:
[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
然后当我查看状态时,它们工作正常并显示活动和运行。然后我重新启动服务器,我再次检查状态,但我得到了这个:
[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.
[ec2-user@ip-10-193-117-56 system]$
所以我不明白,这是什么问题。为什么重启服务器后找不到服务?它们应该被启用并启动一次,然后它们应该自动启动。
任何想法 ?
以下是文件夹中的两项服务:
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