Solved

Restarting a process/application when stopped/rebooted

Posted on 2004-04-26
9
1,140 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

734 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