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

Installing an Intrusion Detection System (IDS) and Reporting Interface

An intrusion detection system (IDS) can perform log analysis, check file integrity, monitor policy changes, and keep an eye out for rootkit installations and alert you when a threat is first suspected. The IDS that I chose for my host was OSSES HIDS, an open source host-based Intrusion Detection System offered by Trend Micro. Here’s how I installed OSSEC on my hosted Linux VPS and Splunk on a local Windows machine to monitor.

The jaw-dropping 3D murals by John Pugh

He works on a large scale in public and residential areas and his paintings can be seen all over the world from New Zealand to Hawaii – with many telling a story of the area where they are positioned. Pugh is used to people’s amazed reactions when they pass his murals. He said: ‘They say “wow did you see that. I thought that was real.” ‘Public art can link people together and stimulate a sense of pride within the community. ‘These life-size illusions allow me to communicate with a very large audience.