Show More
@@ -30,20 +30,29 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): | |
|
51 | if 'unlink' in postexecargs and os.path.exists(postexecargs['unlink']): | |
|
43 | 52 |
|
|
44 | 53 |
|
|
45 | 54 | |
|
46 |
|
|
|
55 | fd = os.open(postexecargs['unlink'], | |
|
47 | 56 |
|
|
48 | 57 |
|
|
49 | 58 |
|
@@ -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