Major rework to facilitate use with supervisord.