2

My software runs on a single phusion-baseimage -based docker image. It consists of a couple of processes that are controlled by runit. For one of these processes/services (rqworker), I need to launch multiple instances based on a deployment-specific configuration (which is simply the number of parallel rqworkers). To me it seems runit does not support setting the number of instances launched for each service.

Are there any ways around this within runit itself or am I better off running something like supervisord as a runit service and letting it take care of the rqworkers?

0

The multi-process service can be wrapped easily by using this principle:

  • final command shall not be producing errors, so it can be sleep infinity instead of real process.
  • the other commands are executed as background jobs using &

This snippet show how it works. Put it to /etc/service/your-service/run and make it runnable, and then replace the cmd at line 5 with your rqworker calls.

#!/bin/bash
# have in env: WORKER_COUNT=7
for i in $(seq 1 $WORKER_COUNT)
do
  sleep $((i + 100)) &
done
sleep infinity

ps afx:

   21 pts/0    S+     0:00 /usr/bin/runsvdir -P /etc/service
   26 ?        Ss     0:00  \_ runsv json-server
 2525 ?        S      0:00      \_ /bin/bash ./run
 2527 ?        S      0:00          \_ /bin/bash ./run
 2541 ?        S      0:00          |   \_ sleep 101
 2528 ?        S      0:00          \_ /bin/bash ./run
 2540 ?        S      0:00          |   \_ sleep 102
 2529 ?        S      0:00          \_ /bin/bash ./run
 2539 ?        S      0:00          |   \_ sleep 103
 2530 ?        S      0:00          \_ /bin/bash ./run
 2538 ?        S      0:00          |   \_ sleep 104
 2531 ?        S      0:00          \_ /bin/bash ./run
 2537 ?        S      0:00          |   \_ sleep 105
 2532 ?        S      0:00          \_ /bin/bash ./run
 2536 ?        S      0:00          |   \_ sleep 106
 2533 ?        S      0:00          \_ /bin/bash ./run
 2535 ?        S      0:00          |   \_ sleep 107
 2534 ?        S      0:00          \_ sleep infinity

If this sleep infinity hack is embarrassing, just replace it with some brilliant information changing sleep infinity into

bash -c 'exec -a softagram-is-cool-and-hip-until sleep infinity' &

..and we are done:

     2533 ?        S      0:00          \_ /bin/bash ./run
     2535 ?        S      0:00          |   \_ your-kick-ass-service-1
     2535 ?        S      0:00          |   \_ your-kick-ass-service-2
     2534 ?        S      0:00          \_ softagram-is-cool-and-hip-until infinity
  • Thanks for the proposal! I think the approach kind of fights against the reasons why runit and/or supervisord are used at all in the first place, which is, taking responsibility and control of keeping the processes running, restarting them if they become unresponsive and so on. – Matti Mäki Apr 12 at 5:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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