Thursday, December 19, 2019

Enabling rc.local in systemd (RHEL 7, CentOS 7)

The rc.local service is stopped by default in CentOS/RHEL 7. If you check the etc/rc.d/rc.local configuration file, there are hints about this.

[root@server1 ~]# cat /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
echo "Hi this is rc.local file"
touch /var/lock/subsys/local

1. Change the permission of the file /etc/rc.d/rc.local so that it has execute permission
[root@server1 ~]# chmod -v +x /etc/rc.d/rc.local
mode of ‘/etc/rc.d/rc.local’ retained as 0755 (rwxr-xr-x)

2.Enabled the service 
[root@server1 ~]# systemctl enable rc-local

3. Reboot the server and check whether the service is executed.
[root@server1 ~]# systemctl status rc-local
 rc-local.service - /etc/rc.d/rc.local Compatibility
   Loaded: loaded (/usr/lib/systemd/system/rc-local.service; static; vendor preset: disabled)
   Active: active (exited) since Fri 2019-12-20 11:30:53 IST; 8min ago

Dec 20 11:30:53 server1.example.com systemd[1]: Starting /etc/rc.d/rc.local Compatibility...
Dec 20 11:30:53 server1.example.com rc.local[1141]: Hi this is rc.local file
Dec 20 11:30:53 server1.example.com systemd[1]: Started /etc/rc.d/rc.local Compatibility.







No comments: