Topic: Daemon / Startup Question

Hi guys,

i wrote a small app to communicate to a Beckhoff buscoupler via TCP/IP. This device will set outputs and read inputs.

That app works nicely if i logon to the router and start it. It will run in an infinity loop (request input state, do logic, send TCP/IP string to set the outputs) and then i sleep(1) before i jump back to the beginning of the loop to start again.

At the beginning i used a cron-job (without the infinity loop), but the problem is, the cronjob can only run every 1 min.

So now, i thought about to make a script that calls the program during start.

like this:
root@OpenWrt:/etc/init.d# vi helloworld
#!/bin/sh /etc/rc.common

START=50
STOP=50

EXTRA_COMMANDS="custom"
EXTRA_HELP="TEST TEST START/STOP HELLOWORLD"

start() {
echo START
cd /bin
/bin/helloworld
}

stop(){
echo stop
kill helloworld
}

custom(){
echo custom funtion
}
~

But i am scared now, because the MY programm will run in that loop and will never come out of it again. Will the router still boot up?

That is the last piece in the puzzle for me wink

thanks a lot in advance
Stefan

Re: Daemon / Startup Question

HI,

got it right with a user from IRC:

A bit dirty maybe, but it works for me wink  I will update the post, if there are improvements.

Thanks to Bastian wink

root@OpenWrt:/etc/init.d# vi helloworld
                return 0
        }

        while true; do
                /bin/helloworld
                sleep 1
                [ -e /tmp/BLABLUBB ] && {
                        rm /tmp/HELLO_WORLD.pid
                        rm /tmp/BLABLUBB
                        exit
                }
        done &

        echo &! >/tmp/HELLO_WORLD.pid

}

stop(){
echo stop
        touch /tmp/BLABLUBB
        while [ -e /tmp/HELLO_WORLD.pid ]; do
                logger -s "$0: waiting for exit"
                sleep 1
        done
}