Quote:
Originally Posted by tayyabq8
Two ways to acheive this:
1) Put your shell commands in a startup file in /etc/rc2.d directly, keep in mind that files residing in /etc/rc2.d follow some rules i.e. filenames starting with S are startup scripts while starting with K are kill scripts, after S or K prefix there comes a 2 digit number like S10 or S65, it tells rc the sequence of startup scripts, so I'll suggest you to give it a name like S99xyz so that it runs in the last and doesn't disturb any other sequence and also is displayed at the bottom of the list of directory.
2)Second way is that create a symbolic link for your script suppose it is at path /home/t1.sh and /etc/rc2.d/S99t1.sh(Startup file)
Choose the best which suits your situation.
Regards,
Tayyab
Do not put the script in the /etc/rc2.d directory, but in the /etc/init.d directory.
In /etc/rc2.d you create a link to the script in /etc/init.d
The script t1.sh should like something like this.
#!/bin/sh
# it is common to write start stop scripts in the bourne shell
# for scripts which are started after all file systems are mounted it doesn't
# really matter. For scripts which are started before, you could end up with
# a problem if that shell is located on a filesystem different than "/"
case $1 in
start) # your code to start the service
;;
stop) # your code to stop the service
esac
or use functions
#!/usr/bin
do_start()
{
# your code to start the service
}
do_stop()
(
# your code to stop the service
}
case $i in
start) do_start
;;
stop) do_stop
;;
esac
Next you create a link in the /etc/rc2.d directory
ln -s /etc/init.d/t1.sh /etc/rc2.d/S99t1.sh
In general files in the /etc/rc<num>.d directory look like:
Snn<name>
Knn<name>
The S indicates the service should be started.
The K indicates the service should be stopped.
nn are 2 digits, and they indicate the order in which services are started or stopped.
Like indicated, 99 would be fine, that way your service is started after all other services.
<name> is usually the same as the name of the script in the /etc/init.d directory.
if /etc/rc2.d/S99t1.sh is linked to /etc/init.d/t1.sh the boot sequence will make sure that when entering run level 2 (that is why the link is in the rc2.d directory), the script /etc/init.d/t1.sh is started with the argument start.
Similar the boot sequence will make sure that all links in a rc<num>.d directory which start with a K will result in executing the script in the /etc/init.d directory they are linked to with as argument "stop" upon entering the run level <num>.
Depending on what kind of service your script will start it is proper to have a "kill" link as well.
Suppose the service is a database, you want the database to be shut down properly, when the system goes down.
To accomplish that you create a K01t1.sh link to /etc/init.d/t1.sh in /etc/rc1.d and/or rc0.d
The reason to put the script in the /etc/init.d directory and to create links in the /etc/rc<num>.d directory is that you do not want to have several copies of the same script in those directories. Instead you use links.
This way, if you want to change your script, you only need to change it in /etc/init.d
Too often it happens that people put the scripts themselves in several /etc/rc<num>.d directories. And after 2 years not even 2 of those copies are identical any more.
/etc/init.d and /etc/rc<num>.d should be used as they are intented to be used.
T