Solved

Restarting a process/application when stopped/rebooted

Posted on 2004-04-26
9
1,144 Views
Last Modified: 2013-12-06
Hi.
Environement : HP-UNIX.
 I would like to auto restart my application whenever it stopped. This should be done automatically as and when the application stopped (intentionally or prematurely).
1. How do I detect when my application is down and write it to the log file?
2. How do I restart the application when it stopped?
2. How do I restart my application when the HP-UNIX is rebooted?
0
Comment
Question by:showbix
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
9 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 10924998

1.  Write a script to continuously check the status, eg:

#!/bin/sh
while true
do
   if ps -ef | grep "[Aa]plication" >/dev/null
   then
         :  # Is running
   else
         echo "Application restarted at `date`" >>/var/log/restart.log
         command to restart application
   fi
   sleep 1
done

2.  Entirely depends on the command to start the application.

3.  Add a startup script to /etc/init.d and /etc/rc3.d directories
0
 

Author Comment

by:showbix
ID: 10925028
Recap back my question.
1. How do I detect when my application is down and write it to the log file?
2. How do I restart my application automatically when it stopped using UNIX command?
3. How do I restart my application when the HP-UNIX is rebooted?
0
 

Author Comment

by:showbix
ID: 10925062
I'm trying to use respawn command in the etc directory so that whenever the UNIX system rebooted, it will restart my application automatically.
jact:2:respawn:/home/myapp/testscript.sh

Is this ok?
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 40 total points
ID: 10925263
I assume you mean an entry in /etc/inittab?

If so, that should work, although you should probably change runlevel 2 to a 3, ie:

jact:3:respawn:/home/myapp/testscript.sh
0
 

Author Comment

by:showbix
ID: 10925851
Hi Tintin.
I have added this script in the "sbin/init.d" directory
-------------------------------------------------------------------------------------------------------------
PATH=/usr/sbin:/usr/bin:/sbin
export PATH


rval=0


set_return() {
        x=$?
        if [ $x -ne 0 ]; then
                echo "EXIT CODE: $x"
                rval=1  # script FAILed
        fi
}


case $1 in
'start_msg')
        # Emit a _short_ message relating to running this script with
        # the "start" argument; this message appears as part of the checklist.
        echo "Starting the ACTIFF"
        ;;
'stop_msg')
        # Emit a _short_ message relating to running this script with
        # the "stop" argument; this message appears as part of the checklist.
        echo "Stopping the ACTIFF"
        ;;

'start')

        # source the system configuration variables
        if [ -f /etc/rc.config ] ; then
                . /etc/rc.config
        else
                echo "ERROR: /etc/rc.config defaults file MISSING"
        fi

        # Check to see if this script is allowed to run...
        if [ "$START_ACTIFF" != 1 ]; then
                rval=2
        else

        # Execute the commands to start ACTIFF
                echo "<<<< startACTIFF.sh >>>>" -- `date` >> /home/ACTIFF/actiff.log
                cd /home/ACTIFF; ./startACTIFF.sh >> /home/ACTIFF/actiff.log
        fi
        ;;

'stop')
        # source the system configuration variables
        if [ -f /etc/rc.config ] ; then
                . /etc/rc.config
        else
                echo "ERROR: /etc/rc.config defaults file MISSING"
        fi

        # Check to see if this script is allowed to run...
        if [ "$START_ACTIFF" != 1 ]; then
                rval=2
        else
        :
        # Execute the commands to stop ACTIFF
                echo "<<<< stopActiff.sh >>>>" -- `date` >> /home/ACTIFF/actiff.log
                cd /home/ACTIFF; ./stopActiff.sh >> /home/ACTIFF/actiff.log
        fi
        ;;

*)
        echo "usage: $0 {start|stop|start_msg|stop_msg}"
        rval=1
        ;;
esac

exit $rval
-------------------------------------------------------------------------------------------------------------

I have added this symbolic link in the "sbin/rc3.d" directory
lrwxrwxrwx   1 root       sys             19 Apr 27 06:30 actiff -> /sbin/init.d/actiff


I have added this file named "actiff" in the "etc/rc.config.d" directory
--------------------------------------------------------------------------------------------------------
#!/sbin/sh
#
#                ACTIFF daemon. (Activation From Field)
#
#                This variable must be set to 1 if you are running ACTIFF.
#                If the variable is false, device files will not be
#                created at boot time and ASAS may not be able to
#                function.
START_ACTIFF=1
--------------------------------------------------------------------------------------------------------

Unfortunately my application (actiff) does not starting up when I reboot the Server. What is the cause of the failure?




0
 
LVL 21

Accepted Solution

by:
tfewster earned 35 total points
ID: 10931373
mv /sbin/rc3.d/actiff /sbin/rc3.d/S999actiff          #S=start  & 999 is the sequence number, showing what order the scripts should be run in; HP-UX will ignore anything that doesnt follow this convention)

However, if you have a `respawn` command in inittab, you don't need to start it in the rc startup sequence.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10934063
tfewster beat me to the explaination.
0
 
LVL 21

Expert Comment

by:tfewster
ID: 10942375
Hmmm - I just clarified a minor point.  Tintin did most of the work, so I will post a request in CS to get the points awarded to him
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question