• 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. mountpoint Command Examples in Linux
  2. How to Enable Remote Desktop to Share the Current Desktop Session in CentOS/RHEL 7
  3. nmcli: command not found
  4. How to monitor the status of dm-multipathing and multipath devices (path groups) in Linux
  5. CentOS / RHEL 6 : How to Disable / Enable direct root login via telnet
  6. How to Configure NFS Services (server-side) to Run on Static Ports as an Alternative CentOS/RHEL 7
  7. scrot Command Examples in Linux
  8. Honeypot Tutorials – Modes and Working of Honeypot
  9. lvm Command Examples in Linux
  10. telinit Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • ctags: Generates an index (or tag) file of language objects found in source files for many popular programming languages
  • csvtool: Utility to filter and extract data from CSV formatted sources
  • csvstat: Print descriptive statistics for all columns in a CSV file
  • csvsql: Generate SQL statements for a CSV file or execute those statements directly on a database

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright