1822542 Members
2862 Online
109642 Solutions
New Discussion юеВ

making a startup script

 
khilari
Regular Advisor

making a startup script

Hi people, actually i have to make a start up script for a particular service. Now, i have the command.
Now, what do i do with it.
What i think i have to make a file in /sbin/rc2.d and make a file like S002 and then just put the command in it. And also make k002 so that the command is killed at shutdown time.
Any suggestions.
5 REPLIES 5
Pupil_1
Trusted Contributor

Re: making a startup script

put the script in /sbin/init.d/ and have a soft link from the appropriate rcx.d directory to start and stop.

Eg.
/sbin/init.d/script is the startup script.
create a soft link in /sbin/rc3.d/ as S999script to start the script in rc3
and
softlink in /sbin/rc2.d/ as K999script to stop the script in rc2.
There is always something new to learn everyday !!
DCE
Honored Contributor

Re: making a startup script


there is a template in /sbin/init.d that you can use for the main script. Put you stop and start commands in the script, as well as the name of the flag file you will create in /etc/rc.config.d

Once you have your script complete, link it to /sbin/rc3.d for the start and to /sbin/rc2.d for the stop. the numbers of the S and K links should add up to 1000

ie S900app and K100app

the file in /etc/rc.config.d contains a variable set to either 1 or 0 - this tells the script to run (1), and not to run (0)

See existing scripts for detailed examples

Tim Nelson
Honored Contributor

Re: making a startup script

There is a template file in /sbin/init.d called template.

-copy that file to something like myservice. -make your new file executable.
-edit that file to include your startup and shutdown commands and change the CONTROL_VARIABLE to a variable name of your choice.
-create a file in a file /etc/rc.config.d/myservice this file contains your variable that you just defined =1. i.e. myservice_var=1

-in /sbin/rc3.d create a link to /sbin/init.d/myservice . i.e. ln -s /sbin/init.d/myservice S900myservice

-in /sbin/rc2.d create a link to /sbin/init.d/myservice . i.e. ln -s /sbin/init.d/myservice K900myservice



-You are done.

Mel Burslan
Honored Contributor

Re: making a startup script

you put the commad which will start and stp the service, usually in /sbin/init.d (not a requirement but a good habbit of system admininstration. Then you need to create symbollic links from rcX.d in the form of SXXXmyscript.sh and KXXXmyscript.sh. One thing you need to keep in mind : the rcX.d level for SXXX link should be one higher than KXXX link, i.e., if your service starts at rc3.d with SxxxMyService.sh, it should be killed in rc2.d with Kxxx script.
________________________________
UNIX because I majored in cryptology...
A. Clay Stephenson
Acclaimed Contributor

Re: making a startup script

Well, you are slightly close.

First cd to /sbin/init.d and copy the file "template" to another file, e.g. myscript

Now modify myscript to do what it is you want to do. You will see 4 sections inside a case statement start_msg) what to print while the machine is booting and starting your service. start) Actual startup for your service. stop_msg) what to print while the machine is stopping your servide during shutdown. stop) Actual shutdown commands for your service.

You should also create a file something like /etc/rc.config.d/myscript that contains any control variables that your startup/shutdown scripts might need. A very common convention is something like
MY_CONTROL_VAR=1 # set to 1 if myscript should actually run

Next, text your script by manually executing it;
e.g. /sbin/init.d/myscript start {or stop}

Finally, you create symbolic links in the rc directories to start/stop your scripts. Normally, if you start at run-level N, you stop at run-level N - 1; also your 'K' 3-digit numbers and your 'S' 3-digit numbers should sum to 1000. This conventions tends to correctly order the start/stop sequence. In your example, and assumming that starting early in run-level 2 is correct (which is doubtful) the links would look like this:

ln -s /sbin/init.d/myscript /sbin/rc2.d/S002myscript
ln -s /sbin/init.d/myscript /sbin/rc1.d/K998myscript
If it ain't broke, I can fix that.