Running linux scripts and services during CentOS / Redhat/ Fedora startup

Running commands and shell scripts on startup/boot

Do you need to run a set of commands or a shell script on CentOS / RHEL / Fedora startup?  The easiest way to start a script upon boot is by adding the command to /etc/rc.local (a symbolic link to /etc/rc.d/rc.local).  /etc//rc.local is a script executed after the initial startup services have been executed.

Here’s an example of the /etc/rc.local script:

#!/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

Auto start services on startup/boot

To auto start services in Centos or Redhat OS, you can use builtin chkconfig utility. It is located in /sbin directory. If you are a regular user (non-root), then /sbin may not be in your path. Therefore, you may have to use the full path to access the chkconfig utility.

To auto start a new service:

  • Find out the name of service’s script from /etc/init.d/ directory e.g. mysqld or httpd
  • Add it to chkconfig

    sudo /sbin/chkconfig –add mysqld
  • Make sure it is in the chkconfig.

    sudo /sbin/chkconfig –list mysqld
  • Set it to autostart

    sudo /sbin/chkconfig mysqld on

To stop a service from auto starting on boot

  • sudo /sbin/chkconfig mysqld off

Leave a Reply

Related Post

The Secret in the Bible book puzzle solution

The Secret in the Bible by Tony Bushby has quite a few factual errors and is more of an atheist “push my agenda” type of book rather than a historical review of the subject matter. There was one interesting aspect to the book though. It included a “puzzle” whereby each of the sixteen chapters contained a secret word that when put together in a sentence reveals ancient knowledge so secret, Bushby was not allowed to outright reveal them in his book for fear of some sort of extremely viscous retribution from someone (boy, have I got news for him).

Create new directories and subdirectories in Unix using a single terminal command

It’s funny how programmers get in a "rut", using the same old coding habits and command line syntax for years on end.  I just found that you can create new directories and subdirectories with a single Unix mkdir command using the -p parm. mkdir -p top_level_directory/child_directory/another_child_directory And if you’re curious, this won’t work (I tried […]

8 Great Netcat (nc) unix commands

Netcat or nc (the command) is a networking utility for debugging and investigating a network, typically by creating and utilizing raw TCP/IP connections.  Known as “The Swiss Army Knife for TCP/IP”, nc is used to read or write to network connections using TCP or UDP. It’s raw features include: Outbound or inbound connections, TCP or […]