Operating System - Linux
1828297 Members
3972 Online
109975 Solutions
New Discussion

Re: halting some application

 
SOLVED
Go to solution
Muhammad Shamroze
Frequent Advisor

halting some application

Hello,
We want to halt some application through scripts...for example when we shutdown the server ...first it run the script and halt the application and then it shutdown the server..so i want to know where we will reside the halting script so that it works while shutting down the server
9 REPLIES 9
g33k
Valued Contributor

Re: halting some application

if run any command the first what system do is checking directories in PATH variable

so make a script for shuting aplication and on the end give shutdown command....

find where halt is, it should be in /usr/bin or /sbin

so make ln -s your_script /bin/halt

now because /bin is before /usr/bin or /sbin (check PATH) so it will run your script...
Muhammad Shamroze
Frequent Advisor

Re: halting some application

one thing more i want to tell u that im using Redhat Linux AS 4.....
Muhammad Shamroze
Frequent Advisor

Re: halting some application

Thanks for reply as u r not getting what im trying to say i want to shutdown some of my services automated mean to say when i run init 6 all my services which i mentioned in my script should also shutdown
g33k
Valued Contributor

Re: halting some application

as I said you create script with lines:

services sshd stop
.
.
.

/sbin/halt (or where is your original halt)

and you name this script as halt and place it in /bin

it's OK if you know your sevices and it's OK

other way is make script which, find services you wanna stop before halting system....
ps will give you list of services... then grep, and cut will help you to find PIDs of services you wanna stop and next you stop them with kill PID or (but it's not very nice kill -9 PID)

here is documentation which will help you with scripts... http://www.tldp.org/LDP/abs/html/

man grep
man ps
man kill

will help you with commands you will need...
anyway if something is unclear you can ask
Atul Gautam
Valued Contributor
Solution

Re: halting some application

Hi Muhammad,

What OS do you have....??

If you have linux, then the best way is to put the script at the location "/etc/init.d/<script>"

After this, go to /etc/rc.d/rc0.d/ and create a symlink to the file using the command ---

ln -s /etc/rc.d/rc0.d/

The reason behind is simple, when we halt the system, it changes the init level to 0 and after that it reads the directory rc0.d where it finds all the KILL SCRIPTS that needs to be stopped, so when it will find your script as well, it will stop that particular process/service.


--
Atul
g33k
Valued Contributor

Re: halting some application

plus to atul those scripts should be executable...
Muhammad Shamroze
Frequent Advisor

Re: halting some application

Thanks for reply
I tried this to put in rc0.d directory, some how it is not working. But if I put this script in rc6.d and shutdown the system with init 6 command it performs well and doing all which I mentioned in script.Do u think is there any problem in K number which number I should use.Also one thing when I tried with S number in rc0.d directory it call the script but all services goes down before activating this script so many resources it can't find which is necessary for this script.
Manuel Wolfshant
Trusted Contributor

Re: halting some application

I suggest reading the man page of init. It will clarify for you the order in which scripts are executed
Atul Gautam
Valued Contributor

Re: halting some application

Hey Muhammad,

As you have specified that when you put S in front of this script, it is killed at the end and few other services that are needed for this script to run are killed before this one gets executed.

So, to resolve this problem, after S try putting in a no. like 01, so that it will be the first to get executed and all other scripts will get executed after this but it may be possible that you may have to change the nos. present on other scripts as well.



--
Atul