##// END OF EJS Templates
add --daemon option to serve command. for issue 45....
Vadim Gelfer -
r1740:f9565438 default
parent child Browse files
Show More
@@ -543,10 +543,12 b' serve [options]::'
543
543
544 options:
544 options:
545 -A, --accesslog <file> name of access log file to write to
545 -A, --accesslog <file> name of access log file to write to
546 -d, --daemon run server in background, as a daemon
546 -E, --errorlog <file> name of error log file to write to
547 -E, --errorlog <file> name of error log file to write to
547 -a, --address <addr> address to use
548 -a, --address <addr> address to use
548 -p, --port <n> port to use (default: 8000)
549 -p, --port <n> port to use (default: 8000)
549 -n, --name <name> name to show in web pages (default: working dir)
550 -n, --name <name> name to show in web pages (default: working dir)
551 --pid-file <file> write server process ID to given file
550 -t, --templatedir <path> web templates to use
552 -t, --templatedir <path> web templates to use
551 -6, --ipv6 use IPv6 in addition to IPv4
553 -6, --ipv6 use IPv6 in addition to IPv4
552
554
@@ -2022,6 +2022,16 b' def serve(ui, repo, **opts):'
2022 if opts[o]:
2022 if opts[o]:
2023 ui.setconfig("web", o, opts[o])
2023 ui.setconfig("web", o, opts[o])
2024
2024
2025 if opts['daemon'] and not opts['daemon_pipefd']:
2026 rfd, wfd = os.pipe()
2027 args = sys.argv[:]
2028 args.append('--daemon-pipefd=' + str(wfd))
2029 pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0),
2030 args[0], args)
2031 os.close(wfd)
2032 os.read(rfd, 1)
2033 os._exit(0)
2034
2025 try:
2035 try:
2026 httpd = hgweb.create_server(repo)
2036 httpd = hgweb.create_server(repo)
2027 except socket.error, inst:
2037 except socket.error, inst:
@@ -2040,6 +2050,24 b' def serve(ui, repo, **opts):'
2040 ui.status(_('listening at http://%s:%d/\n') % (addr, port))
2050 ui.status(_('listening at http://%s:%d/\n') % (addr, port))
2041 else:
2051 else:
2042 ui.status(_('listening at http://%s/\n') % addr)
2052 ui.status(_('listening at http://%s/\n') % addr)
2053
2054 if opts['pid_file']:
2055 fp = open(opts['pid_file'], 'w')
2056 fp.write(str(os.getpid()))
2057 fp.close()
2058
2059 if opts['daemon_pipefd']:
2060 wfd = int(opts['daemon_pipefd'])
2061 os.write(wfd, 'y')
2062 os.close(wfd)
2063 sys.stdout.flush()
2064 sys.stderr.flush()
2065 fd = os.open(util.nulldev, os.O_RDWR)
2066 if fd != 0: os.dup2(fd, 0)
2067 if fd != 1: os.dup2(fd, 1)
2068 if fd != 2: os.dup2(fd, 2)
2069 if fd not in (0, 1, 2): os.close(fd)
2070
2043 httpd.serve_forever()
2071 httpd.serve_forever()
2044
2072
2045 def status(ui, repo, *pats, **opts):
2073 def status(ui, repo, *pats, **opts):
@@ -2476,11 +2504,14 b' table = {'
2476 "^serve":
2504 "^serve":
2477 (serve,
2505 (serve,
2478 [('A', 'accesslog', '', _('name of access log file to write to')),
2506 [('A', 'accesslog', '', _('name of access log file to write to')),
2507 ('d', 'daemon', None, _('run server in background')),
2508 ('', 'daemon-pipefd', '', ''),
2479 ('E', 'errorlog', '', _('name of error log file to write to')),
2509 ('E', 'errorlog', '', _('name of error log file to write to')),
2480 ('p', 'port', 0, _('port to use (default: 8000)')),
2510 ('p', 'port', 0, _('port to use (default: 8000)')),
2481 ('a', 'address', '', _('address to use')),
2511 ('a', 'address', '', _('address to use')),
2482 ('n', 'name', '',
2512 ('n', 'name', '',
2483 _('name to show in web pages (default: working dir)')),
2513 _('name to show in web pages (default: working dir)')),
2514 ('', 'pid-file', '', _('name of file to write process ID to')),
2484 ('', 'stdio', None, _('for remote clients')),
2515 ('', 'stdio', None, _('for remote clients')),
2485 ('t', 'templates', '', _('web templates to use')),
2516 ('t', 'templates', '', _('web templates to use')),
2486 ('', 'style', '', _('template style to use')),
2517 ('', 'style', '', _('template style to use')),
General Comments 0
You need to be logged in to leave comments. Login now