comparison mercurial/cmdutil.py @ 10012:2bfe1a23dafa

cmdutil: service: add appendpid parameter to append pids to pid file
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Tue, 01 Dec 2009 11:28:31 +0900
parents 2e67734e1453
children 2b630e4c8f2f
comparison
equal deleted inserted replaced
10011:a9836feb5a8c 10012:2bfe1a23dafa
556 ui.warn(_('(consider using --after)\n')) 556 ui.warn(_('(consider using --after)\n'))
557 557
558 return errors 558 return errors
559 559
560 def service(opts, parentfn=None, initfn=None, runfn=None, logfile=None, 560 def service(opts, parentfn=None, initfn=None, runfn=None, logfile=None,
561 runargs=None): 561 runargs=None, appendpid=False):
562 '''Run a command as a service.''' 562 '''Run a command as a service.'''
563 563
564 if opts['daemon'] and not opts['daemon_pipefds']: 564 if opts['daemon'] and not opts['daemon_pipefds']:
565 rfd, wfd = os.pipe() 565 rfd, wfd = os.pipe()
566 if not runargs: 566 if not runargs:
586 586
587 if initfn: 587 if initfn:
588 initfn() 588 initfn()
589 589
590 if opts['pid_file']: 590 if opts['pid_file']:
591 fp = open(opts['pid_file'], 'w') 591 mode = appendpid and 'a' or 'w'
592 fp = open(opts['pid_file'], mode)
592 fp.write(str(os.getpid()) + '\n') 593 fp.write(str(os.getpid()) + '\n')
593 fp.close() 594 fp.close()
594 595
595 if opts['daemon_pipefds']: 596 if opts['daemon_pipefds']:
596 rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] 597 rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')]