Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Restarting a process/application when stopped/rebooted

Posted on 2004-04-26
9
Medium Priority
?
1,146 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 160 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 140 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
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…
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.:

670 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