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