I'm running Red Hat 5.1. I have a script called sysinit that I added as a service using chkconfig --add sysinit. I have the following set in the file:

#chkconfig 4 01 01

This creates one symlink in my rc4.d directory for S01sysinit. However, I want the script to be run on startup and shutdown. No matter what I do, I cannot get a custom script (Service) to run on shutdown. I even tried separating out my functionality into two scripts, one to run at S01 and the other to run at K01 but it didn't work. I don't want to have to resort to modifying the rc.sysinit file to do what my script should be doing (I shouldn't have to touch that I would think). The reason I need to do this is because I need to unmount a samba share inside the /opt directory before the rc.sysinit file tries to unmount the /opt directory (right now I get "device is busy" failures because the cifs mount is still there).

Is there something special I need to do so that my script can run on startup and on shutdown and reboot? Can I have a K01sysinit and S01sysinit in the same run level? Or am I misunderstanding how run levels work?

I have the sections for )start and )stop already in the script.

  • This is what I found in my search online. It's about the only thing I haven't tried yet so it might be the solution I'm looking for. It said I needed to add this line to my file: "touch /var/lock/subsys/<scriptname>" since the etc/rc.d/rc file is looking for it when it tries to execute scripts from the symlinks marked with K*.
    – sqenixs
    Nov 11, 2011 at 4:18

2 Answers 2


Yes, you should have both S and K at the same time. The K scripts should be run when leaving the said level. The search terms you may want to use would be "System V Init" or "telinit" .

Is chkconfig installing the symbolic links as expected?

  • No, it does not create the K symbolic links. Only the S ones.
    – sqenixs
    Nov 11, 2011 at 3:23
  • man chkconfig says what you have should be right. Your comment about the /var/lock/subsys file is also true, but the first step is getting the symlink there. Nov 13, 2011 at 4:47
  • The other thing I missed was the following line in my script #chkconfig 4 99 01 which is how it knows where to set the symlinks.
    – sqenixs
    Nov 17, 2011 at 17:18

The solution I found was to add the following code:

    touch /var/lock/subsys/<scriptname> 

The etc/rc.d/rc file was looking for the lock file when it tried to execute scripts from the symlinks marked with K*. Without that file, the system doesn't know that the "service" is "running".

  • This could create problems as next time the script lock is found again, the script would not run at the startup. Is not it? I would suggest to use /etc/rc.d/rc.local, since it is executed everytime the runlevel is changed even by init. Dec 6, 2011 at 5:02
  • No, because I have additional code to remove the lock file in the service. So when leaving a run level, rc.sysinit finds the lock file so it knows that the service is running and executes "stop" on it. My service then removes the lock file. This will get called no matter what run level I am changing to, as long as the K** symlink exists. Now, unless the system crashes, I think I'm okay (not sure if lock files persist in the system if it crashes).
    – sqenixs
    Dec 6, 2011 at 5:07
  • Oh ok, still I would configure the service under chkconfig with chkconfig --add and then chkconfig 4 service on. Also update the service script's chkconfig header such a way that service is started at the end with least priority and killed in the beginning of the shutdown sequence with high priority. (Not 01 01) Dec 6, 2011 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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