5

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:

#!/bin/bash
#
# 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
Boris
  • 101
  • 2
  • 6

5 Answers5

10

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:

#!/bin/sh
# chkconfig: 345 98 11
# description: my auto start-stop script.

echo "my service is doing something :)" >> /root/tempfile
case "$1" in
 start)
  echo "my service started" >> /root/tempfile
  touch /var/lock/subsys/myservice
  echo "OK"
  ;;
 stop)
  echo "my service stoped" >> /root/tempfile
  rm -f /var/lock/subsys/myservice
  echo "OK"
  ;;
esac
  • 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
  • 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! –  Jun 08 '11 at 18:44
  • In this case you should mark Bogdan's answer as accepted. – rvs Jun 24 '11 at 14:32
2

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

shashivm
  • 31
  • 3
  • 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
1

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

Chris
  • 414
  • 2
  • 2
  • The script not being called during shutdown. – Boris Mar 21 '11 at 15:34
  • 1
    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
0

Could you post the header of the script?

Something like this:

#!/bin/sh
#
# /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/MySystem.pid
Bart De Vos
  • 17,761
  • 6
  • 62
  • 81
  • # # 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 – Boris Mar 21 '11 at 12:54
  • sorry, I not success format the code in comments. – Boris Mar 21 '11 at 13:05
0

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!

Caio Cunha
  • 101
  • 2