LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-20-2008, 04:52 PM   #1
ziyunxiao
LQ Newbie
 
Registered: Apr 2008
Posts: 6

Rep: Reputation: 0
Killing my script when system down.


Hi,

I have a script which start at system starts and it suppose to stop itself and send a message to me. It works only for start up, for shutdown it's killed before the stop command is executed by this script. here is what I do.

I have two scripts, one is for start up. for example start.sh
another is for stop, for example stop.sh

My OS is :
[HTML][root@centos5 ~]# uname -a
Linux centos5 2.6.18-53.1.21.el5 #1 SMP Tue May 20 09:34:18 EDT 2008 i686 i686 i386 GNU/Linux[/HTML]

I create a script in /etc/init.d called robinsrv. and run the chkconfig --add robinsrv and added it as a service.

I have tested it by using
[HTML]service robinsrv start
service robinsrv stop
service robinsrv status[/HTML]

everything works fine. when I execute service robinsrv stop I'll receive email.

I let it run on runlevel 345.

[HTML][root@centos5 ~]# chkconfig --list robinsrv
robinsrv 0ff 1ff 2ff 3n 4n 5n 6ff[/HTML]


Now the problem is when the system is down, no email is received from the stop script, it hasn't been executed or it the main process has been killed before stop script get executed. My service doens't rely on any other service(I mean non-system basic service.)

Here is the defalt kill sequece:
[HTML][root@centos5 ~]# find /etc/rc.d -name K??robinsrv
/etc/rc.d/rc6.d/K10robinsrv
/etc/rc.d/rc2.d/K10robinsrv
/etc/rc.d/rc1.d/K10robinsrv
/etc/rc.d/rc0.d/K10robinsrv[/HTML]

it doesn't work then I change rc0, rc6 and create rc3 for kill process as sequence 01. Now it looks like this, but it is still not working.
[HTML][root@centos5 ~]# find /etc/rc.d -name K??robinsrv
/etc/rc.d/rc6.d/K01robinsrv
/etc/rc.d/rc2.d/K10robinsrv
/etc/rc.d/rc1.d/K10robinsrv
/etc/rc.d/rc3.d/K01robinsrv
/etc/rc.d/rc0.d/K01robinsrv[/HTML]

Can any one help me?

Thanks

Robin

Last edited by ziyunxiao; 10-20-2008 at 04:56 PM.
 
Old 10-20-2008, 05:39 PM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Hi.

Chances are sendmail/postfix/exim/whatever is being killed before the message gets through. Might need to add a sleep to your script to allow the email to get through the local MTA.

Dave
 
Old 10-21-2008, 09:26 AM   #3
ziyunxiao
LQ Newbie
 
Registered: Apr 2008
Posts: 6

Original Poster
Rep: Reputation: 0
It seems no effect.

Quote:
Originally Posted by ilikejam View Post
Hi.

Chances are sendmail/postfix/exim/whatever is being killed before the message gets through. Might need to add a sleep to your script to allow the email to get through the local MTA.

Dave
I put sleep in the script but I still didn't get shutdown email.

from the console, I didn't see the message that my service is shuting down. Thank you anyways.

Does anyone know where is the system shutdown log? I only know startup message can found by dmesg.

Robin
 
Old 10-21-2008, 11:28 AM   #4
ziyunxiao
LQ Newbie
 
Registered: Apr 2008
Posts: 6

Original Poster
Rep: Reputation: 0
Finally I found the reason

The RC process will check /var/lock/subsys to see whether the service lock file exists, if so call K?? script else skip.

After I create the lock file with same name of the service then It works as wish.

Thanks anyways.

Robin
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
killev script not killing defunct evolution ender42 Ubuntu 1 05-06-2006 10:00 AM
killing a hung up process with a script lockejr Linux - General 2 04-13-2006 11:40 PM
Shell-Script for killing processes oulevon Programming 4 02-14-2006 10:49 AM
Process killing script owix Linux - General 2 07-19-2005 11:08 AM
Killing X Blindly (by Script)? negface Slackware 38 10-01-2004 09:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration