Show More
@@ -30,26 +30,35 b' def runservice(opts, parentfn=None, init' | |||
|
30 | 30 | runargs=None, appendpid=False): |
|
31 | 31 | '''Run a command as a service.''' |
|
32 | 32 | |
|
33 | postexecargs = {} | |
|
34 | ||
|
35 | if opts['daemon_postexec']: | |
|
36 | for inst in opts['daemon_postexec']: | |
|
37 | if inst.startswith('unlink:'): | |
|
38 | postexecargs['unlink'] = inst[7:] | |
|
39 | elif inst.startswith('chdir:'): | |
|
40 | postexecargs['chdir'] = inst[6:] | |
|
41 | elif inst != 'none': | |
|
42 | raise error.Abort(_('invalid value for --daemon-postexec: %s') | |
|
43 | % inst) | |
|
44 | ||
|
33 | 45 | # When daemonized on Windows, redirect stdout/stderr to the lockfile (which |
|
34 | 46 | # gets cleaned up after the child is up and running), so that the parent can |
|
35 | 47 | # read and print the error if this child dies early. See 594dd384803c. On |
|
36 | 48 | # other platforms, the child can write to the parent's stdio directly, until |
|
37 | 49 | # it is redirected prior to runfn(). |
|
38 | 50 | if pycompat.iswindows and opts['daemon_postexec']: |
|
39 | for inst in opts['daemon_postexec']: | |
|
40 | if inst.startswith('unlink:'): | |
|
41 | lockpath = inst[7:] | |
|
42 | if os.path.exists(lockpath): | |
|
43 | procutil.stdout.flush() | |
|
44 | procutil.stderr.flush() | |
|
51 | if 'unlink' in postexecargs and os.path.exists(postexecargs['unlink']): | |
|
52 | procutil.stdout.flush() | |
|
53 | procutil.stderr.flush() | |
|
45 | 54 | |
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
55 | fd = os.open(postexecargs['unlink'], | |
|
56 | os.O_WRONLY | os.O_APPEND | os.O_BINARY) | |
|
57 | try: | |
|
58 | os.dup2(fd, 1) | |
|
59 | os.dup2(fd, 2) | |
|
60 | finally: | |
|
61 | os.close(fd) | |
|
53 | 62 | |
|
54 | 63 | def writepid(pid): |
|
55 | 64 | if opts['pid_file']: |
@@ -109,15 +118,8 b' def runservice(opts, parentfn=None, init' | |||
|
109 | 118 | except AttributeError: |
|
110 | 119 | pass |
|
111 | 120 | |
|
112 | lockpath = None | |
|
113 | for inst in opts['daemon_postexec']: | |
|
114 | if inst.startswith('unlink:'): | |
|
115 | lockpath = inst[7:] | |
|
116 | elif inst.startswith('chdir:'): | |
|
117 | os.chdir(inst[6:]) | |
|
118 | elif inst != 'none': | |
|
119 | raise error.Abort(_('invalid value for --daemon-postexec: %s') | |
|
120 | % inst) | |
|
121 | if 'chdir' in postexecargs: | |
|
122 | os.chdir(postexecargs['chdir']) | |
|
121 | 123 | procutil.hidewindow() |
|
122 | 124 | procutil.stdout.flush() |
|
123 | 125 | procutil.stderr.flush() |
@@ -137,8 +139,8 b' def runservice(opts, parentfn=None, init' | |||
|
137 | 139 | |
|
138 | 140 | # Only unlink after redirecting stdout/stderr, so Windows doesn't |
|
139 | 141 | # complain about a sharing violation. |
|
140 | if lockpath: | |
|
141 |
os.unlink( |
|
|
142 | if 'unlink' in postexecargs: | |
|
143 | os.unlink(postexecargs['unlink']) | |
|
142 | 144 | |
|
143 | 145 | if runfn: |
|
144 | 146 | return runfn() |
General Comments 0
You need to be logged in to leave comments.
Login now