Find the answer to your Linux question:
Results 1 to 8 of 8
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Start & Stop daemons in runlevels

    I am experiencing a problem a problem trying to stop a daemon when the machine reboots or halts.

    I have a script /etc/init.d/myprogram. This is then soft linked /etc/rc6.d/K99myprogram and /etc/rc0.d/K99myprogram. Within /etc/init.d, if I run "./myprogram stop," I see the script does go through the process of halting the process however, when I run reboot or halt the system, I don't see any behavior.

    Any help would be greatly appreciated on how to resolve this issue.

  2. #2
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Adding the soft link to the folder wont work, you need to use the following command:

    sudo update-rc.d PROGRAM defaults
    Where PROGRAM is the executable in /etc/init.d/
    Linux User #453176

  3. #3


    According to the man pages:
    If defaults is used then update-rc.d will make links to start the  service  in 
    runlevels  2345 and to stop the service in runlevels 016.
    I've manually soft linked stuff to /etc/rc[016].d in Ubuntu. The version I'm currently using is Red Hat ES 4 which is having this problem.

  4. $spacer_open
  5. #4
    K99 will be run last of all, I think, so if the rest of the system has already shutdown, your script won't work. Generally, K-scripts should be number "100 - n" where n is the S-script number.

  6. #5
    I run Red Hat and have had similar problems. For the life of me I can't remember the exact reason why. The thing I did learn was to use chkconfig to set up the symlinks. Look at the manpage for details. You'll have put a couple of lines in the start/stop script for chkconfig as comments.

    # chkconfig: 345 44 56
    # description: Listen and dispatch ACPI events from the kernel

  7. #6


    Actually guys, the script is K89myscript. Not to make this into a debate but my attempt with this on Debian GNU/Linux has worked perfectly.

    radmin@redhat# ls /etc/rc6.d
    K01tog-pegasus         K25sshd        K74nscd            K92arptables_jf
    K02cups-config-daemon  K30sendmail    K74ntpd            K92iptables
    K02haldaemon           K35vncserver   K75netfs           K94diskdump
    K02NetworkManager      K35winbind     K85mdmonitor       K95kudzu
    K03messagebus          K40smartd      K85mdmpd           K95openibd
    K03rhnsd               K44rawdevices  K86nfslock         K96pcmcia
    K05anacron             K50netdump     K87auditd          K99cpuspeed
    K05atd                 K50xinetd      K87irqbalance      K99lvm2-monitor
    K05saslauthd           K56acpid       K87portmap         K99microcode_ctl
    K10cups                K60crond       K88syslog          K99readahead
    K10dc_server           K68rpcidmapd   K88wpa_supplicant  K99readahead_early
    K10psacct              K69rpcgssd     K89netplugd        K99sysstat
    K10xfs                 K72autofs      K89rdisc           S00killall
    K12dc_client           K73ypbind      K89tis             S01reboot
    K15gpm                 K74apmd        K90bluetooth
    K20nfs                 K74ipmi        K90network
    K24irda                K74lm_sensors  K91isdn
    As you can see, there are multiple K<nn> scripts in this directory. Even when I stand in front of the console and do a reboot, I don't see all of these services stop.

    As to my understanding, any scripts with that begins with K stops and S starts. K99 might be the last script to stop but it should stop.

    In addition, I've tried making the scripts with chkconfig. It worked perfectly fine but the end result was the same as what I would have done manually.

    Any thoughts?
    Last edited by sprucio; 09-22-2008 at 02:40 PM. Reason: made an error with code

  8. #7
    How are you shutting down the system?
    With shutdown or init 0.

    Also, I'd suggest you put in the script an echo that writes to a file to verify it's not being run. Something like:

    date > /tmp/myscript.log
    echo "myscript stop" >> /tmp/myscript.log

  9. #8

    Red Hat

    Hi guys,

    It seems like this is a Red Hat issue as far as I can tell. I've tested this in Debian and Ubuntu and the desired behavior works out fine.

    I've discovered the solution through the help of another member from this forum. If you do a search on my name, you should find another thread that explains this.

    Basically, Red Hat creates files in /var/lock/subsys and pending on if the file exists, then it'll kill the appropriate services in the appropriate runlevels.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts