Which part is looping?
If it's trying to start over and over, try replacing return 0
with exit 0
If it get's stuck in the:
while [ `ps ax | egrep -c "ctdaemon"` -le 1 ]
section, then try printing out the output of ps ax|egrep "ctdaemon"
to see if it is returning what you are expecting.
Remeber -le is less than or equal to