Solved

Restarting a process/application when stopped/rebooted

Posted on 2004-04-26
9
1,126 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
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:showbix
Comment Utility
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
Comment Utility
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
Comment Utility
tfewster beat me to the explaination.
0
 
LVL 20

Expert Comment

by:tfewster
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
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…
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…
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.

744 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

17 Experts available now in Live!

Get 1:1 Help Now