'Run a program as a long-running background process.
Args:
path [string]: Path to the program to run.
args [list of string]: Arguments to pass to program
detach [bool]: True if we\'re running it in separate process group.
A separate process group will continue after we exit.'

@staticmethod
def run_daemon(path, args, detach=True, environ=None):

    pid = os.fork()
    if (pid == 0):
        if detach:
            os.setsid()
    else:
        return pid
    maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
    if (maxfd == resource.RLIM_INFINITY):
        maxfd = 1024
    for fd in range(3, maxfd):
        try:
            os.close(fd)
        except OSError:
            pass
    os.execve(path, args, (environ or os.environ))
