LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Stange behaviour noted when using service (http://www.linuxquestions.org/questions/linux-general-1/stange-behaviour-noted-when-using-service-713675/)

hhilo2002 03-22-2009 10:27 PM

Stange behaviour noted when using service
 
Hi all,

I am using linux service to start a program. However different behaviors are observed when the service is started automatically upon startup/reboot and when the service is called manually through "service myservice start".

Script to startup my program(Name:myprog)
-----------------------------------------------------------
1 while(application is down)
2 do
3 "start my application" #script will stop here if program is running(script can still be found when i perform a "ps"
4 echo "rebooting" >> log.txt
5 done

Startup script(Name:myservice)
-----------------------------------------------------------
Simply call myprog


Via startup/reboot
------------------------------------------------------------
The application gets started however, in the event when the application crashes, the script will terminate at line 3 instead of printing out "rebooting" in log.txt. When i perform a "ps", both the script and program can no longer be found.

Via manual startup-"service myservice start"
------------------------------------------------------------
The application also gets started. However when the application crashes, the same script continue with line 4 and "rebooting" is printed in log.txt. When i perform a "ps",both the script and program can still be found.

I have done all the necessary setup, eg creating a service script(myservice) in /etc/init.d, and adding it using chkconfig.

Sorry for the long post.

Any help is greatly appreciated! Please advise.

Cheers!

sundialsvcs 03-22-2009 10:44 PM

Your startup-script should not be looping. There should be no "while" logic here.

The only purpose of the scripts that are invoked to carry out a "service start|stop|restart" request should be to do exactly what is requested of them... once. It is not their responsibility to do: "while my application is down..."

Other system services are responsible for observing when and if a service is running, and to determine that it should be restarted.

Take an existing example of such a script and pattern your work after it exactly. Don't add anything to it, and don't take anything away.

hhilo2002 03-22-2009 11:28 PM

Just to clarify my earlier post.

Script to startup my program(Name: myprog)
-----------------------------------------------------------
1 while(application is down)
2 do
3 "start my application" #script will stop here if program is running(script can still be found when i perform a "ps"
4 echo "rebooting" >> log.txt
5 done

Startup script(Name: myservice)
-----------------------------------------------------------
Simply call myprog

hhilo2002 03-23-2009 02:34 AM

please advise..thanks


All times are GMT -5. The time now is 02:37 AM.