RHEL7: How to configure a rc-local service.

Share this link

Presentation

With Systemd, the Init scripts are not there any more. Consequently, the execution of tasks at boot time had to change.

Hopefully, a nice solution has been found: it uses the good old rc.local file.

The Solution

Now, to execute tasks at boot time, you put them into the /etc/rc.d/rc.local file.
Then, you change the execution permissions on this file:

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

Besides allowing executions of tasks, this simple operation activates the new rc-local Systemd service for all the future boots (this is like systemctl enable in Systemd language).

Finally, you can start the rc-local service and, this way, test the execution of the rc.local file:

# systemctl start rc-local

SSD optimization is a good example of such a rc-local service.

Useful Tips

In addition, Ed Greshko and several others provided several interesting ideas:

  • put these lines at the beginning of the rc.local script to redirect the error messages:
    #!/bin/bash
    exec 2> /tmp/rc.local.log      # send stderr from rc.local to a log file
    exec 1>&2                      # send stdout to the same log file
    echo "rc.local started"        # show start of execution
    set -x                         # tell sh to display commands before execution
  • write this line at the end of the rc.local script to prove no error stopped the execution:
    echo "rc.local completed"
1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 4.80 out of 5)
Loading...

Leave a Reply

RHCSA7: Task of the day

Allowed time: 3 minutes.
Check that you've got no SELinux policy violations.

RHCE7: Task of the day

Allowed time: 10 minutes.
Configure a httpd server that executes a Perl script in the /var/www/cgi-bin directory displaying "Hello!".

Follow me on Twitter

Poll for favorite RHEL 7 book

What is your favorite RHEL 7 book to prepare RHCSA & RHCE exams?

View Results

Loading ... Loading ...

Poll for most difficult RHCSA 7 topic

What do you think is the most difficult RHCSA 7 topic?

View Results

Loading ... Loading ...

Poll for most difficult RHCE 7 topic

What do you think is the most difficult RHCE 7 topic?

View Results

Loading ... Loading ...

Archives