2373 |
2373 |
2374 if repo is None and not ui.config("web", "webdir_conf"): |
2374 if repo is None and not ui.config("web", "webdir_conf"): |
2375 raise hg.RepoError(_("There is no Mercurial repository here" |
2375 raise hg.RepoError(_("There is no Mercurial repository here" |
2376 " (.hg not found)")) |
2376 " (.hg not found)")) |
2377 |
2377 |
2378 if opts['daemon'] and not opts['daemon_pipefds']: |
2378 class service: |
2379 rfd, wfd = os.pipe() |
2379 def init(self): |
2380 args = sys.argv[:] |
2380 try: |
2381 args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) |
2381 self.httpd = hgweb.server.create_server(parentui, repo) |
2382 pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), |
2382 except socket.error, inst: |
2383 args[0], args) |
2383 raise util.Abort(_('cannot start server: ') + inst.args[1]) |
2384 os.close(wfd) |
2384 |
2385 os.read(rfd, 1) |
2385 if not ui.verbose: return |
2386 os._exit(0) |
2386 |
2387 |
2387 if httpd.port != 80: |
2388 httpd = hgweb.server.create_server(parentui, repo) |
2388 ui.status(_('listening at http://%s:%d/\n') % |
2389 |
2389 (httpd.addr, httpd.port)) |
2390 if ui.verbose: |
2390 else: |
2391 if httpd.port != 80: |
2391 ui.status(_('listening at http://%s/\n') % httpd.addr) |
2392 ui.status(_('listening at http://%s:%d/\n') % |
2392 |
2393 (httpd.addr, httpd.port)) |
2393 def run(self): |
2394 else: |
2394 self.httpd.serve_forever() |
2395 ui.status(_('listening at http://%s/\n') % httpd.addr) |
2395 |
2396 |
2396 service = service() |
2397 if opts['pid_file']: |
2397 |
2398 fp = open(opts['pid_file'], 'w') |
2398 cmdutil.service(opts, initfn=service.init, runfn=service.run) |
2399 fp.write(str(os.getpid()) + '\n') |
|
2400 fp.close() |
|
2401 |
|
2402 if opts['daemon_pipefds']: |
|
2403 rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] |
|
2404 os.close(rfd) |
|
2405 os.write(wfd, 'y') |
|
2406 os.close(wfd) |
|
2407 sys.stdout.flush() |
|
2408 sys.stderr.flush() |
|
2409 fd = os.open(util.nulldev, os.O_RDWR) |
|
2410 if fd != 0: os.dup2(fd, 0) |
|
2411 if fd != 1: os.dup2(fd, 1) |
|
2412 if fd != 2: os.dup2(fd, 2) |
|
2413 if fd not in (0, 1, 2): os.close(fd) |
|
2414 |
|
2415 httpd.serve_forever() |
|
2416 |
2399 |
2417 def status(ui, repo, *pats, **opts): |
2400 def status(ui, repo, *pats, **opts): |
2418 """show changed files in the working directory |
2401 """show changed files in the working directory |
2419 |
2402 |
2420 Show status of files in the repository. If names are given, only |
2403 Show status of files in the repository. If names are given, only |