How to use rc.local on server with CentOS 8 Stream

First you need to understand the term “rc”. Its original meaning is “run commands”. This is mainly used to run commands on system boot “rc.local” is a script that contains commands to be run on system boot.

As far as Linux distributions are concerned, you may well need to test the systems before launching them. To do this, it is worth taking into account the important rc.local file in order to put the appropriate and necessary commands there. This is necessary in order to make it possible to execute them at system startup.

How to use RC.local on CentOS 8

Update your system

yum update

Initially, you should check the status of the “rc-local” service. To do this, enter the following special command:

systemctl status rc-local

The answer will be unequivocal: the service is inactive. The next step is to create the rc-local file inside systemd. You can do it like this:

nano /etc/systemd/system/rc-local.service

Then you need to just copy and paste the following content inside it by CTRL+S and CTRL+X

[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target

Then, after the successful actions taken earlier, you need to make the file executable. This means that the commands will be executed. Follow the instructions below:

chmod +x /etc/rc.local

Enable and start the rc-local service using the commands below.

systemctl enable rc-local

Then you need to start the service and also get the status with the following command:

systemctl start rc-local
systemctl status rc-local

Once you have successfully started the service, you can then access the “/etc/rc.local” file with a text editor. We used the nano editor for this. Use the following command:

nano /etc/rc.local

The file is now in open format, and you can then enter commands at the end of the file. All these commands will be executed when the server starts. We have created a directory and a text file inside that directory, as seen in the image above. After that, it is recommended to restart the rc.local service as follows.

systemctl restart rc-local

After rebooting the system, you will see that the required directory and file will be created in the specified location.

chmod +x /etc/rc.d/rc.local

Was this article helpful?

Related Articles

Leave A Comment?