I am trying to implement an rc.d(8) service script that starts multiple processes. The exact number of processes is determined dynamically from an rc.conf(5) variable like so:
I read the tutorial Practical rc.d scripting in BSD, but there is no example with multiple processes.
What would be a practical and simple approach?
I am thinking about doing a loop and then defining "name", "command", "pidfile", etc. multiple times to generate multiple services within a single script:
Is this approach OK or are there any pitfalls? Is it a bad idea to generate multiple services from a single script?
dummy_process_count=5
I read the tutorial Practical rc.d scripting in BSD, but there is no example with multiple processes.
What would be a practical and simple approach?
I am thinking about doing a loop and then defining "name", "command", "pidfile", etc. multiple times to generate multiple services within a single script:
Bash:
#!/bin/sh
. /etc/rc.subr
: ${dummy_process_count:=0}
for k in seq $dummy_process_count; do
name="dummy${k}"
eval ": \${${name}_enable:=no}"
pidfile="/var/run/${name}.pid"
start_cmd="/path/to/executable/dummy instance=${k}"
stop_cmd=":"
load_rc_config $name
run_rc_command "$@"
done
Is this approach OK or are there any pitfalls? Is it a bad idea to generate multiple services from a single script?