How do I create a service using chkconfig in CentOS?

39,373

Solution 1

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

Solution 2

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.

Solution 3

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
Share:
39,373
qroberts
Author by

qroberts

Updated on September 18, 2022

Comments

  • qroberts
    qroberts almost 2 years

    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?