LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-28-2008, 01:51 AM   #1
immortaltechnique
Member
 
Registered: Oct 2006
Location: Kenya
Distribution: Ubuntu, RHEL, OpenBSD
Posts: 287

Rep: Reputation: 32
Call init script on exception


Morning all,

I was wondering is there an easy way of calling back an init script to an application that develops an exception error? For instance, instead of always having to kill the application when it throws an exception, is there a way to kill it when the exception occurs and call the init script to restart the application?

My idea was to have a value say > 0 when the exception occurs and then when the init script receives a similar value it restarts the app.


Much appreciation.
 
Old 11-28-2008, 02:37 AM   #2
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
AFAIK there is no application that currently checks services to see if they exited cleanly or not.

You could probably write a quick script to see if the process is running, but how you would know if it exited cleanly or not (when the script wasn't the thing to start the process) I'm not sure.

Here's a start:
Code:
#!/bin/bash
###
### Monitor script
###
SERVICE=syslogd
RESTART_SERVICE="/etc/init.d/sysklogd -start"

count_proc=$(ps -ef|grep ${SERVICE}|grep -v grep|wc -l)

if [ $count_proc -eq 0 ]
then
   echo "Restart $SERVICE"
   $RESTART_SERVICE
fi
EDIT:-

The script would need to run as root on a regular basis via cron. Ofcourse if the cron daemon is the process you want to check, you would need to loop and sleep instead.

Last edited by Disillusionist; 11-28-2008 at 02:41 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ssh - using variables in call to start remote script from local script babag Linux - Networking 2 06-03-2008 05:50 PM
How can I script an autologin, automatically call kde(or simillar) and call an app aboaventura Slackware 8 02-04-2007 12:00 AM
exception handeling in script reach2tripplek Programming 1 05-02-2006 03:26 AM
How to call a script from a system startup script? jonatito Linux - Newbie 7 11-11-2005 10:40 PM
Does init 5 call startx? linuxlah Linux - General 4 03-05-2003 12:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:14 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