Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have wrote script /etc/init.d/xxx which start/stop my service on CentOS 5.5.

When I call 'service start xxx' or 'service stop xxx' everything works fine. But when I restart my machine, I see in the logs that on shutdown the service was not stopped.

However, it started on boot.

> chkconfig --list xxx 
 xxx  0:off   1:off   2:on    3:on    4:on    5:on    6:off

What I am doing wrong. Thank you.

UPD: the header of the script:

# Startup script for the xxx
# chkconfig: 345 99 01
# description: This script ...

# Provides: xxx
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Should-Start:
share|improve this question

I am not a linux guru, more of a noob actually, but in order to execute the shutdown script you must create a lock file in /var/lock/subsys/ folder in your startup script. I found the answer here: CentOS Forum

Script example:

# chkconfig: 345 98 11
# description: my auto start-stop script.

echo "my service is doing something :)" >> /root/tempfile
case "$1" in
  echo "my service started" >> /root/tempfile
  touch /var/lock/subsys/myservice
  echo "OK"
  echo "my service stoped" >> /root/tempfile
  rm -f /var/lock/subsys/myservice
  echo "OK"
share|improve this answer
Bogdan!!! You migh not be a linux Guru But you have the right answer - i was nearly quitting doing this stuff when i found your post and I confirm - without lockfile in /var/lock/subsys/ the service will start but never stop ... which in my case led to a lovely kernel panic!!! Thanks a lot! – user83972 Jun 8 '11 at 18:44
In this case you should mark Bogdan's answer as accepted. – rvs Jun 24 '11 at 14:32
Also, you need to make sure that your lock file has the same name as the startup script. – Mr. Muskrat May 17 '12 at 23:18

You might have to create a link in /etc/rc6.d/ directory, so that it will call that script when shutting down the server.

ls -l /etc/rc5.d/K60nfs

lrwxrwxrwx 1 root root 13 May 13 2010 /etc/rc5.d/K60nfs -> ../init.d/nfs

share|improve this answer
That is what chkconfig does. While is possible chkconfig failed, it's fairly unlikely and would indicate a much bigger problem. – Scott Pack Mar 21 '11 at 12:44
All links are present. Also, I thought it is in the responsibility of chkconfig – Boris Mar 21 '11 at 13:05

When you say it's not being shut down, do you know if the script is never being called or if it's just not doing what it's supposed to?

On top of other logs, I'd add a bunch of echo statements to the startup/shutdown script that just do things like:

echo "$(date) Entering script" >> ~root/debugging.log
echo "$(date) Entering section x" >> ~root/debugging.log

Might help you track down where to look for the problem

share|improve this answer
The script not being called during shutdown. – Boris Mar 21 '11 at 15:34
So I'm a bit confused as to why the output of your two commands is a a bit off. The first (chkconfig) says it should be running in level 2,3,4,5. The header of the script says levels 3,4,5. But this is probably nothing. Can you also run 'ls /etc/rc?.d/[SK]*xxx' ?(where xxx is the servicename) – Chris Mar 22 '11 at 19:34

Could you post the header of the script?

Something like this:

# /etc/init.d/mysystem
# Subsystem file for "MySystem" server
# chkconfig: 2345 95 05 
# description: MySystem server daemon
# processname: MySystem
# config: /etc/MySystem/mySystem.conf
# config: /etc/sysconfig/mySystem
# pidfile: /var/run/
share|improve this answer
<code> # # Startup script for the xxx # # chkconfig: 345 99 01 # description: This script ... # ### BEGIN INIT INFO # Provides: xxx # Required-Start: $local_fs $network # Required-Stop: $local_fs $network # Should-Start: ### END INIT INFO </code> – Boris Mar 21 '11 at 12:54
sorry, I not success format the code in comments. – Boris Mar 21 '11 at 13:05

Bogdan Olteanu answers maybe the answer for your case, it was in mine. The lock file must have the same name of the start up script so CentOS can shut it down. In your hypothetically case, you should have this line in your start method:

touch /var/lock/subsys/xxx

Must be exactly the same name of the service (xxx).

Cheers, CaioToOn!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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