Solved

Restarting a process/application when stopped/rebooted

Posted on 2004-04-26
9
1,131 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 20

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 20

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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 get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now