
Redhat サーバーで、起動時にデータベースを開始し、シャットダウン時にデータベースを停止する 2 つのサービスをセットアップしようとしているので、/etc/systemd/system
次の 2 つのファイルを配置しました。
シャットダウンサービス:
[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
答え1
この問題の解決策は、次の操作を実行して SELinux 機能を無効にすることです (永続的に無効化)。
vi /etc/sysconfig/selinux
次に、指令をSELinux=enforcing
次のように変更します。SELinux=disabled
再起動するとsestatus
、無効になっていることが表示されます。