linuxembedded-linuxfedorainit.dinittab

Restarting a linux app using a respawn entry in inittab does not work


Scenario:
I have a process running on linux which is started in the background by a script hooked up at /etc/init.d/ called as MyApp which is just a shell script without the .sh. Following is my init.d script script

#!/bin/sh

PARAM=$1

case ${PARAM} in
    start)
        MyApp &
        ;;
    stop)
        killall -9 MyApp
        ;;
    *)
        echo "Usage: $0 {start|stop}" >&2
        exit 1
        ;;
esac

As you can see it starts MyApp in the background.

Objective and problem:
I want to restart MyApp when it crashes. I tried to find out how that is done. Looks like I have to add an entry into /etc/inittab from various links I read. So I added the following entry into /etc/inittab.

MyApp:12345:respawn:MyApp

Question:
Above does not seem to work and how can I get this to work correctly? What is the wrong that I am doing here?

Note:
I am doing a killall -9 MyApp and expeciting it to restart because of the entry I added to /etc/inittab. Is this expectation correct?


Solution

  • case ${PARAM} in
        start)
            (while :; do MyApp ;done) &
            ;;