38

I am trying to add to the auto start at boottime a linux service through the

chkconfig -add <servicename> 

and I get a message saying

service <servicename> does not support chkconfig

I am using Red Hat Enterprise 4. The script I am trying to add to the autostart at boottime is the following:

#!/bin/sh

soffice_start() {   if [ -x /opt/openoffice.org2.4/program/soffice ]; then
        echo "Starting Open Office as a Service"
        #echo " soffice -headless -accept=socket,port=8100;urp;StarOffice.ServiceManager
-nofirststartwizard"
        /opt/openoffice.org2.4/program/soffice
-headless -accept="socket,host=0.0.0.0,port=8100;urp;StarOffice.ServiceManager"
-nofirststartwizard &   else
        echo "Error: Could not find the soffice program. Cannot Start SOffice."   fi }

soffice_stop() {   if [ -x /usr/bin/killall ]; then
        echo "Stopping Openoffice"
        /usr/bin/killall soffice 2> /dev/null   else
        echo "Eroor: Could not find killall.  Cannot Stop soffice."   fi }

case "$1" in  'start')    soffice_start    ;;  'stop')    soffice_stop    sleep 2    ;;  'restart')    soffice_stop    sleep 5  soffice_start    ;;  *)    if [ -x /usr/bin/basename ]; then
        echo "usage: '/usr/bin/basename $0' start| stop| restart"    else
        echo "usage: $0 start|stop|restart"    fi esac
1
  • is your service in init.d/
    – Rungano
    Jun 22, 2009 at 15:12

4 Answers 4

81

The script must have 2 lines:

# chkconfig: <levels> <start> <stop>
# description: <some description>

for example:

# chkconfig: 345 99 01
# description: some startup script

345 - levels to configure
99 - startup order
01 - stop order

After you add the above headers you can run chkconfig --add <service>.

3
  • The extra space on the second line was added by markdown, it is not needed
    – katriel
    Jun 22, 2009 at 15:19
  • 2
    Here is some more information on the Run Levels and other things. tldp.org/HOWTO/HighQuality-Apps-HOWTO/boot.html
    – FilBot3
    Aug 21, 2014 at 21:00
  • 1
    The above doesn't seem to add the proper kill scripts though. I need chkconfig <service> --level 06 off to explicitly get the kill scripts.
    – user239558
    May 24, 2019 at 8:42
6

While katriel has already answered this with the bare minimum needed to create an init script, I think you'd also be well served with looking at /etc/init.d/skeleton and using that as a template on which to base your init script. You'll end up with a much more consistent and readable script.

2
  • 6
    Theoretically good advice, but /etc/init.d/skeleton is not present on RHEL systems, only on Debian and related (Ubuntu, I think).
    – Harlan
    Feb 18, 2011 at 16:09
  • according to this post there isn't a an /etc/init.d/skeleton file since 2018, and the template is the example shown in the manual of the init-d-script interpreter
    – rellampec
    Oct 21, 2022 at 6:49
1

It sounds like Geo's specific problem has already been solved, but I ran into a similar message while trying to set up a Rails app with sidekiq as a managed service. I'll explain my solution here in case it helps any other newbies like me.

I'm working on a CentOS install, and chkconfig is already set up with several other services like httpd, mysql, and redis. Note that most services need only be enabled on runlevels 3 through 5.

chkconfig --list
> httpd             0:off   1:off   2:on    3:on    4:on    5:on    6:off
> mysqld            0:off   1:off   2:on    3:on    4:on    5:on    6:off
> redis-server      0:off   1:off   2:on    3:on    4:on    5:on    6:off
> (etc...)

I needed to add a new script for the sidekiq service, so I grabbed the script at https://gist.github.com/CD1212/5326706, modified it to fit my app's parameters, and saved it at /etc/rc.d/init.d/sidekiq (owned by root like all the other scripts there).

However when I tried to register this new service, I got the chkconfig error:

sudo chkconfig --add sidekiq
> service sidekiq does not support chkconfig

After some extra reading I discovered that the priority numbers defined at the top of each chkconfig script must be unique. A clearer error message would have been nice! Another script had shutdown priority level 75, so I changed mine to 76 and tried again. Here's the head of my init script:

#!/bin/bash
#
# sidekiq    Init script for Sidekiq
#
# chkconfig: 345 99 76
# processname: sidekiq
# pidfile: /var/www/visual_testing_tool/sidekiq.pid
# description: Starts and Stops Sidekiq message processor for the Rails app.
#

This time, sudo chkconfig --add sidekiq gave no complaint. Then when I ran sudo chkconfig --list sidekiq, the sidekiq service was shown as on for the appropriate runlevels.

0

The priority numbers do not need to be unique. They only represent an order of services.

ls -l /etc/rc.d/rc3.d/*oracle lrwxrwxrwx 1 root root 16 Sep 16 12:28 /etc/rc.d/rc3.d/S99oracle -> ../init.d/oracle

ls -l /etc/rc.d/rc3.d/*it
lrwxrwxrwx 1 root root 12 Sep 16 12:36 /etc/rc.d/rc3.d/S99it -> ../init.d/it

Chkconfig did not have an issue adding the "it" service. Otherwise you would be limited to 100 services.

Also in my example, it would run before oracle because the scripts are run alphabetically.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .