0

I'm trying to set up in a Redhat server, 2 services that start a database at startup, and stop it at shutdown, so I have put 2 files under /etc/systemd/system as follows:

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

then I did these commands:

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

then when I look at the status, they work fine and show active and running. I then reboot the server, and I check again the status but I get this:

[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]$

So I don't understand, what is the issue. Why the services aren't being found after rebooting the server ? they are supposed to be enabled and started once, then they should start automatically.

Any idea ?

Here are both services inside the folder:

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
3
  • Why the shutdown "service"? Why don't you just define shutdown and start in one service unit? Apr 26, 2023 at 17:53
  • what do you mean ? they are not triggered by the same triggers. that's not the question here.
    – Souad
    Apr 27, 2023 at 12:42
  • You don't need two service definitions to start and stop a service. Both should be handled by the same unit file. Apr 27, 2023 at 12:46

1 Answer 1

0

The answer to this issue is to disable SELinux feature by doing the following ( permanent disabling) :

vi /etc/sysconfig/selinux

Then change the directive SELinux=enforcing to SELinux=disabled

Reboot then : sestatus, it should now show it is disabled.

1
  • Disabling selinux is not a solution. Create a selinux module to allow what you need to do instead. Apr 27, 2023 at 12:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .