Sunday, June 7, 2015

Generating the simplest possible nginx load-balancing config

I recently had to put together a load-balancing configuration for nginx and wish that I had a shell script to generate the very simplest possible nginx setup.  I think I have it now:

:
if [ -z "$1" ]; then
echo "Usage: $0 URI HOST1 HOST2 ..."
exit 1
fi
uri="$1"
shift
hosts=$@
out=/etc/nginx/nginx.conf
if [ ! -f $out.bak ]; then
        mv $out $out.bak
fi
cat <<EOF > $out
events {
}
http {
        upstream configuration_servers {
EOF

for h in $hosts; do
        echo "                server $h:8080;"
done >> $out

cat <<EOF >> $out
        }
        server {
                listen       80;
                location $uri {
                proxy_pass http://configuration_servers$uri;
                }
        }
}
EOF

cat $out

service nginx restart

url=localhost:80$uri
if ! curl $url; then
        echo "$0: curl $url failed, exiting..." 1>&2
        exit 1
fi

Monday, January 12, 2015

Sending strangers and anonymous callers to voicemail in Google Voice

I normally only write about software development in this blog, but I can't resist adding a software configuration recipe that I have found useful for cutting back on unwanted callers getting through to me via Google voice and my android phone. This problem recently became much worse when I acquired a new phone number which had previously been used by a woman named Melody, a Bay Area woman who apparently ran up lots of debts.

I can understand that you would need to have a won't-take-no-for-an-answer kind of personality to work as a debt collector, but wow those people are not fun to talk to. But I didn't want to just block strangers and anonymous callers, since once in a while those calls are legitimate. Doctors offices, for example, typically call anonymously in order to protect the privacy of their patients. So what I really wanted to do was to send all those folks directly to voicemail.

Sounds simple enough, and I was readily assured that this was possible, but I never did catch up with an explicit recipe to do it.

So here is one:

  • Browse to Google voice settings
  • on the Phones tab, disable all of your devices (i.e., uncheck the checkbox associated with each)
  • on the Voicemail & Text tab, click the edit button for the special Callers group "All Contacts"
  • enable all devices that you want to ring when one of your contacts calls you
That's it!