[rabbitmq-discuss] "service rabbitmq-server start" hangs when using python's Popen from subprocess.

Tim Watson tim at rabbitmq.com
Tue Oct 16 14:29:27 BST 2012


On 16/10/2012 14:25, Raphaël De GIUSTI wrote:
> It seems that the following line in /etc/init.d/rabbitmq-server script
> is the cause of the Popen hang
>
>              setsid sh -c "RABBITMQ_PID_FILE=$PID_FILE $DAEMON > \
>                  ${INIT_LOG_DIR}/startup_log 2>
>     ${INIT_LOG_DIR}/startup_err" &
>
>

Yes ok that makes sense, but you didn't say anything about popen 
hanging, but rather proc.communicate() hanging, which is why I suggested 
it's the i/o redirection. If popen doesn't like setsid and friends 
(i.e., nohup) then I suspect you're a bit stuck.

> If I modify the script so it does not use setsid sh -c, the subprocess
> call does not hang anymore, but I expect side-effects if I do this.
>
>              RABBITMQ_PID_FILE=$PID_FILE $DAEMON > \
>                  ${INIT_LOG_DIR}/startup_log 2>
>     ${INIT_LOG_DIR}/startup_err &
>
>

Well a daemon is not supposed to be running in the shell that calls 
`service <name> start` so it's wrong to change the init script. As I 
said, you can invoke the rabbitmq-server start script (which the init 
script calls) by hand if you like.

> Any idea on how to fix it with my python Popen method ?
>
> On Tue, Oct 16, 2012 at 2:15 PM, Raphaël De GIUSTI
> <raphael.degiusti at guardis.com <mailto:raphael.degiusti at guardis.com>> wrote:
>
>     Well, I have the same problem when subprocessing
>     "/etc/init.d/rabbitmq-server start".
>
>     Note that I have no problem subprocessing "service rabbitmq-server
>     status" or "service rabbitmq-server stop" (or any other service).
>
>     My only issue is with the start method of
>     /etc/init.d/rabbitmq-server init script.
>
>
>
>
>     On Tue, Oct 16, 2012 at 1:34 PM, Tim Watson <tim at rabbitmq.com
>     <mailto:tim at rabbitmq.com>> wrote:
>
>         When you run RabbitMQ on an rpm based distro using /sbin/service
>         then the init script is going to redirect stdio, as you would
>         expect for a service/daemon. You'll need to start RabbitMQ
>         directly from the ./scripts/rabbitmq-server shell script I
>         guess, if you want to grab stdio - or tail the logs?
>
>         On 16 Oct 2012, at 11:47, Raphaël De GIUSTI wrote:
>
>          > Hi everyone,
>          >
>          > Starting the rabbitmq-server service with python's Popen from
>         subprocess makes it hang.
>          >
>          > Here's the little snippet to reproduce it (tested on Fedora
>         16 + Python2.7 and Centos 6.3 + Python2.6)
>          >
>          > from subprocess import PIPE, Popen
>          > proc = Popen('service rabbitmq-server start', shell=True,
>         stderr=PIPE, stdout=PIPE)
>          > print proc.communicate()
>          >
>          > Problem is with "stdout=PIPE", I think.
>          >
>          > The following snippet works, using proc.wait()
>          >
>          > from subprocess import PIPE, Popen
>          > proc = Popen('service rabbitmq-server start', shell=True,
>         stderr=PIPE, stdout=PIPE)
>          > print proc.wait()
>          >
>          > Any idea on how to fix it using proc.communicate() because I
>         need feedback from the "subprocess.PIPE" ?
>          >
>          > Thank you.
>          >
>          > Raphael
>          > _______________________________________________
>          > rabbitmq-discuss mailing list
>          > rabbitmq-discuss at lists.rabbitmq.com
>         <mailto:rabbitmq-discuss at lists.rabbitmq.com>
>          >
>         https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>
>         _______________________________________________
>         rabbitmq-discuss mailing list
>         rabbitmq-discuss at lists.rabbitmq.com
>         <mailto:rabbitmq-discuss at lists.rabbitmq.com>
>         https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>
>
>
>
>
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>



More information about the rabbitmq-discuss mailing list