I'm sure you've moved on... but... Here's what I just did to modify the stock openvpn init script for centos 6/7
Basically, if you have more config files than number of processors/cores, just randomize the core you start the process on and hope for the best distribution possible.
If you have more processors/cores than config files, then just start at core 0 and work your way up to the max config file and you've guaranteed to run each process on a different core.
# This comes in flat
numConfFiles=`/bin/ls *.conf 2>/dev/null`
# Unflatten and convert to a number / i.e. count as an array
numConfFiles=(${numConfFiles})
numProcs=`nproc`
if [ "$numConfFiles" -gt "$numProcs" ]; then
# Found more conf files than processors. Randomizing the startup on different cores as best as we can.
for c in `/bin/ls *.conf 2>/dev/null`; do
# Get as close to a random number, with max of $numProcs as we can
coreNum=$((RANDOM % $numProcs))
bn=${c%%.conf}
if [ -f "$bn.sh" ]; then
. ./$bn.sh
fi
rm -f $piddir/$bn.pid
taskset -c $coreNum $openvpn --daemon --writepid $piddir/$bn.pid --config $c --cd $work
if [ $? = 0 ]; then
successes=1
else
errors=1
fi
let coreNum=coreNum+1
done
else
# We have at least as many cores as we do conf files, so we can just start them in order and ensure
# we have 1 process per core runnning.
coreNum=0
for c in `/bin/ls *.conf 2>/dev/null`; do
bn=${c%%.conf}
if [ -f "$bn.sh" ]; then
. ./$bn.sh
fi
rm -f $piddir/$bn.pid
taskset -c $coreNum $openvpn --daemon --writepid $piddir/$bn.pid --config $c --cd $work
if [ $? = 0 ]; then
successes=1
else
errors=1
fi
let coreNum=coreNum+1
done
fi