Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm familiar with making startup scripts in other unix platforms, but redhat 6.1 and 6.2 want to pass a start or stop command to the startup script. I have loaded a program that does not need the start and stop sent to it. The passing of the start kills the program. I just want to have a symbolic link to the programs executable run when the runlevel is reached. Any suggestions?
Distribution: Debian, Red Hat, Slackware, Fedora, Ubuntu
Posts: 13,602
Rep:
First put a file in /etc/rc.d/init.d that looks like the following:
Code:
#!/bin/sh
# Startup script for program
# Source function library.
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo -n "Starting program: "
daemon program
echo
;;
stop)
echo -n "Shutting down program "
killproc program
echo
;;
*) echo "Usage: program {start|stop}"
exit 1
esac
exit 0
Then make soft links to the startup file in the appropriate rcN.d directories, where N is the runlevel. NOTE: If you do not want the program to run as a damon then take out the word daemon before the program name.
I used your script and it works on startup just fine. I now have a problem with the kill scripts. I made a ln -s to rc3.d, rc0.d, and rc6.d and the target was K??programname. ?? being like 01. I want to kill my application before the machine kills the rest of the scripts.Nothing depends on them. I want the script to kill the program on halt, reboot. The startup is obviously only in rc3.d because runlevel 3 is my default. I don't see any thing on the screen saying it killed my program when I halt or reboot. I do see messages on startup. Do you have any ideas? Is linux wierd about using particular numbers in startup and kill scripts in the rc directories?
Distribution: Debian, Red Hat, Slackware, Fedora, Ubuntu
Posts: 13,602
Rep:
When the system changes runlevels it goes into the appropriate dir (we'll say /etc/rc.d/rc0.d for shutdown) and calls each script. If the filename is K99program it will call it with stop (./K99program stop). If the filename is S99program it will call it with start. The files are called in ascending order (starting with x00, ending with x99). You may want to change the echo in the stop case to "Shutting down programname" to make it more noticable.
Run level 0 is halt and runlevel 6 is reboot. You will need to put your link to kill your program in the appropriate directory for these two runlevels to get it to work for both halt and reboot. Putting the kill link in runlevel 3 will not do anything for you. Also if you want the program to run while in X, you will need to put the start link in runlevel 5 also.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.