Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a python script that listens and blocks while it waits for data on a redis list.

It runs fine in upstart using the following:

description "stage message consumer"
author "Nilesh Ashra"

start on started mountall
stop on shutdown

respawn

exec sudo -u user REDIS_HOST=0.0.0.0 ENVIRONMENT=my_env /usr/bin/python /path/to/message_consumer.py

My question is, can I use upstart to spin up say 12 of these?

If not, can you recommend a way to do this?

share|improve this question

2 Answers 2

I could be off on this as it's been awhile since I worked on interpreted language daemons, but I think the "right" way to do this is architect your program to listen to the port then fork another process to handle a bundle of requests/jobs on another port while the parent continues to listen for more connections.

You might want to look for code samples on how to create simple web servers to see how to do something like this. Mailq is right that you can't have multiple processes listen to the same IP and port pair at the same time.

So...fork other work processes that do their jobs then sync back up with a control process.

share|improve this answer

No you can't. You can not listen multiple times on the same port. So if the first instance already occupies the port (let's say 80), then no other instance can listen on the same port.

But even if it is not a TCP/IP-listening daemon it is still a strange requirement. Why would one start a command multiple times in parallel that does exactly the same?

share|improve this answer
    
Not necessarily true. If you use a superserver like xinet you can listen on the port in xinet and have it accept the socket then fork the python processes as children, that way it can inherit the file descriptor. –  Matthew Ife Nov 27 '11 at 21:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.