• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to Execute Scripts/Commands using /etc/rc.d/rc.local in CentOS/RHEL 7

by admin

The Problem

The scripts/commands in the configuration file /etc/rc.d/rc.local could not work at boot time in a CentOS/RHEL 7 system. Same used to work in earlier CentOS/RHEL versions. Is it depricated or is there a workaround to still use this method?

The Answer

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.

# 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.

touch /var/lock/subsys/local

The WorkAround

1. With systemd, the init scripts are not there any more. Consequently, the execution of tasks at boot time had to change. In CentOS/RHEL 7, the /etc/rc.d/rc.local file is controlled by rc-local service.

...
[Unit]
Description=/etc/rc.d/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.d/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.d/rc.local start
TimeoutSec=0
RemainAfterExit=yes

2. By default, the file /etc/rc.d/rc.local don’t have execution permission. Please append the execution permissions to this file.

# ls -l /etc/rc.d/rc.local
-rw-r--r--. 1 root root 473 Nov  8 00:20 /etc/rc.d/rc.local
# chmod +x /etc/rc.d/rc.local
# ls -l /etc/rc.d/rc.local
-rwxr-xr-x. 1 root root 473 Nov  8 00:20 /etc/rc.d/rc.local

3. Enable rc.local service, to make sure it starts every time after a reboot.

# systemctl enable rc-local

Confirm whether the service is enabled:

# systemctl status rc-local.service

3. Then, please start the rc-local service.

# systemctl start rc-local

Filed Under: CentOS/RHEL 7, Linux, OEL 7

Some more articles you might also be interested in …

  1. grub-mkconfig Command Options
  2. How to Customize Linux Password Expiration and Complexity Requirements
  3. e2fsck Command Examples in Linux
  4. How to identify the HBA cards/ports and WWN in Linux
  5. mumble: command not found
  6. How to Enable Thin LVM Automatic Extension
  7. acpi: command not found
  8. dmidecode Command Examples in Linux
  9. Xen Hypervisor (xm) command Cheat Sheet
  10. unzip: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • ncat Command Examples in Linux
  • ncat: command not found
  • nautilus Command Examples in Linux
  • namei: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright