I want to be able to create a service so that the bash script will run every time the server boots up.

I am running CentOS 5.

I have been reading about chkconfig and creating a file in /etc/init.d for chkconfig to handle but I cannot seem to get it to work whenever I 'chkconfig servicename on' and then 'service servicename start'

When I do chkconfig --list my service is listed there.

Can someone provide me with a sample of the file I need to create in /etc/init.d and how to get everything running?

3 Answers 3


If you just need a bash script to run one or more things every time the server starts, you can run the script from /etc/rc.local. Here's mine - it fires up my media server app by calling its startup script:

# 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

#NK make sure nas is mounted:
mount -a
/etc/init.d/serviiod start

There is an initscript template on the Fedora Project website.

On the same page, below the template, are complete instructions for writing headers for initscripts on RedHat/Fedora/CentOS systems. You might need to do this if you need to ensure your script runs after other services are started, you only want the script to run in certain circumstances, or you want graphical system administration tools to display complete information about the script.


Place your script, for example (dctm,dctm_jms) in the path /etc/init.d

chmod +x dctm
chmod +x dctm_jms
chkconfig --add dctm
chkconfig --add dctm_jms
chkconfig --level 345 dctm on
chkconfig --level 345 dctm_jms on

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.