Question

I have created an /etc/init.d script to start a shell script containing a while true loop. Here's the content of the script:

#!/bin/bash
# /etc/init.d/SCRIPT

### BEGIN INIT INFO
# Provides:          SCRIPT
# Required-Start:    $remote_fs $syslog $network
# Required-Stop:     $remote_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start SCRIPT script
# Description:       Sample desc
### END INIT INFO

case "$1" in
    start)
        echo "Starting SCRIPT.."
        /usr/local/bin/SCRIPT/SCRIPT_run.sh
        ;;
    stop)
        echo "Stopping SCRIPT.."
        killall SCRIPT_run.sh
        ;;
    *)
        echo "Usage: /etc/init.d/SCRIPT start|stop"
        exit 1
        ;;
esac

exit 0

Now because the SCRIPT_run.sh contains an infinite loop, when I execute /etc/init.d/SCRIPT start, it doesn't go back to my shell because it's waiting for the script to finish executing. Is there a way to start the script without 'linking' the output to my shell?

Was it helpful?

Solution

You can drop it to the background with &, but it's much safer to use the start-stop-daemon which comes with Debian, and has a the --background option to handle this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top