How do I create a service using chkconfig in CentOS?

5

1

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?

qroberts

Posted 2011-05-16T20:47:10.300

Reputation: 4 609

Answers

4

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:

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

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

Linker3000

Posted 2011-05-16T20:47:10.300

Reputation: 25 670

7

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.

Patches

Posted 2011-05-16T20:47:10.300

Reputation: 14 078

2

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

Jesus villajos

Posted 2011-05-16T20:47:10.300

Reputation: 21