Shell Script – Why Enter is Needed After init.d Script Completes

centosinit-scriptshell-scriptssh

I had to write my own CentOS init.d script for celery because it only ships with one for Debian. You can see the script I wrote when I answered my own stack overflow question 3989656.

But there's a problem with this script. if I invoke it:

sudo service celeryd start

then I need to hit enter to get a shell prompt after it completes. This is a problem because I want to invoke it via ssh from another machine by doing:

ssh 192.168.2.3 sudo service celeryd start

and ssh never returns. (I use fabric to start and stop remote services, and this hangs it because it invokes the ssh command above).

What would cause this behavior, and how do I fix it in my script?

Note that if I do "sh -x /etc/init.d/celeryd" as recommended by Thomas Themel in the comments, the output is:

runuser -s /bin/bash - apache -c 'ulimit -S -c 0 >/dev/null 2>&1 ; /usr/local/django/portalapps/manage.py celeryd --pidfile /var/run/celery.pid -f /var/log/celeryd.log -l INFO'

I don't understand how the daemon function in /etc/init.d/functions (which is what produces this series of bash commands) actually daemonizes the process.

Best Answer

Had the exact same problem - your question and investigations actually helped me find the answer.

Start celery with celery_detach - and, poof! Things work!

ie. manage.py celery_detach --params --settings=foo

It returns immediately, with a proper line break, and the things that fabric is looking for.

Related Question