Running Linux Programs at Boot Time

If, like me, you want to easily have some program start every time you boot up your Linux server, you need to find and edit the rc.local file in your file-system. /etc/rc.local is really a simple place to put shell commands and/or scripts you want to run when booting up.

On my CentOS servers, this file is actually a symlink to /etc/rc.d/rc.local. It is also linked the same way on my main desktop PC, a system running on Fedora.

[me@jenia ~]$ ls -l /etc/rc.local
lrwxrwxrwx 1 root root 13 Mar 19 17:07 /etc/rc.local -> rc.d/rc.local

On my laptop, a Ubuntu system, it is just a regular executable file at /etc/rc.local.

Example rc.local

Recently, I developed a BASH script to block a list of IP addresses from accessing this server. Naturally, I want this script now to run every time this server is boot up. The script was saved to /usr/share/gid/scripts/iproute-block-list.sh on this CentOS server. Next, I edited the rc.local file on this server, and to the bottom of the file, I inserted the command line to run the script.

This is how my server’s rc.local file looks today:

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local


# Inserted by J de Silva on 2013/04/27.
# The following script will block IP addresses and blocks of IP addresses.
/usr/share/gid/scripts/iproute-block-list.sh

If you go through the documentation inside CentOS: Running Additional Programs at Boot Time, you will see that rc.local runs on 2 occasions:

  1. at boot time
  2. when changing runlevels

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>