Example #1
0
def start(path):
    set_signal_handler(exit_handler)

    pid_file = os.path.join(path, 're-proxy.pid')
    log_file = os.path.join(path, 're-proxy.log')

    pid = os.fork()
    assert pid != -1

    if pid > 0:
        sys.exit(0)

    if not with_pid_file(pid_file, os.getpid()):
        sys.exit(1)

    os.setsid()  # TODO What's this
    signal.signal(signal.SIG_IGN, signal.SIGHUP)  # TODO and what's this

    sys.stdin.close()
    try:
        freopen(log_file, 'a', sys.stdout)
        freopen(log_file, 'a', sys.stderr)
    except IOError as e:
        logging.error(e.message)
        sys.exit(1)