I have to run multiple instances of same app with slightly different settings. Only thing that changes is one command line parameter.
So currently I've got script which looks something like this:
[program:thing-one]
command=/usr/local/thing --instance one
user=a_user
stdout_logfile=/var/log/thing.log
autostart=true
autorestart=true
startsecs=10
redirect_stderr=true
directory=/
startretries=1000
[program:thing-two]
command=/usr/local/thing --instance two
user=a_user
stdout_logfile=/var/log/thing.log
autostart=true
autorestart=true
startsecs=10
redirect_stderr=true
directory=/
startretries=1000
[program:thing-three]
command=/usr/local/thing --instance three
user=a_user
stdout_logfile=/var/log/thing.log
autostart=true
autorestart=true
startsecs=10
redirect_stderr=true
directory=/
startretries=1000
How can I avoid repetition of identical settings?
Since there are only three instances of the same program that differ only on one argument, we can employ Python's string expression expansion inside
command
like following.Compared to your configuration, I changed two lines and added one.
Moreover, the docs say you must include said expansion if you use
numprocs
> 1.I doubt this is what your looking for but depending on what your end goals are you could use a script to generate the config. I am a sys admin not a developer so excuse poor coding practices. But this would allow you to just add a single line to add a new app. If you wanted to change any of the existing directives you also would only have to do it once in one place and re-run the script.
Use sed to edit them all at the same time.
sed -i -e 's/numprocs=3/numprocs=4/g' your_conf.conf
or if using vi
shift+V+G
,shift+:+g/numprocs=3/s//numprocs=4/g
Maybe it's not the direct answer but in management it's better to keep each [program:] block in separate file thing-one.conf, thing-two.conf, thing-three.conf.
In case you would like to turn off one instance do
mv thing-two.conf thing-two.conf_off
or remove it permanently. Even grouping similar instances is easier when keeping in separate files.This is just my small exp.