#!/usr/bin/env python3
"""Entry point for hymn-choices gunicorn launcher."""
import os
import sys

if __name__ == '__main__':
    import tomllib

    cfg_path = os.environ.get(
        'HYMN_CHOICES_CONFIG', '/etc/hymn_choices/config.toml',
    )
    with open(cfg_path, 'rb') as fh:
        config = tomllib.load(fh)

    port = config.get('server', {}).get('port', 5101)
    workers = config.get('server', {}).get('workers', 2)

    os.execlp(
        'gunicorn', 'gunicorn',
        '--bind', f'127.0.0.1:{port}',
        '--workers', str(workers),
        '--access-logfile', '-',
        'hymn_choices:create_app()',
    )
