##// END OF EJS Templates
The cluster applications now have a working directory option.....
Brian Granger -
Show More
@@ -37,6 +37,10 b' c = get_config()'
37 # Remove old logs from cluster_dir/log before starting.
37 # Remove old logs from cluster_dir/log before starting.
38 # c.Global.clean_logs = True
38 # c.Global.clean_logs = True
39
39
40 # The working directory for the process. The application will use os.chdir
41 # to change to this directory before starting.
42 # c.Global.working_dir = os.getcwd()
43
40 #-----------------------------------------------------------------------------
44 #-----------------------------------------------------------------------------
41 # Controller launcher configuration
45 # Controller launcher configuration
42 #-----------------------------------------------------------------------------
46 #-----------------------------------------------------------------------------
@@ -35,6 +35,10 b' c = get_config()'
35 # will override the values set for the client and engine connections below.
35 # will override the values set for the client and engine connections below.
36 # c.Global.secure = True
36 # c.Global.secure = True
37
37
38 # The working directory for the process. The application will use os.chdir
39 # to change to this directory before starting.
40 # c.Global.working_dir = os.getcwd()
41
38 #-----------------------------------------------------------------------------
42 #-----------------------------------------------------------------------------
39 # Configure the client services
43 # Configure the client services
40 #-----------------------------------------------------------------------------
44 #-----------------------------------------------------------------------------
@@ -34,6 +34,10 b' c = get_config()'
34 # attribute can be set to the full path of the FURL file.
34 # attribute can be set to the full path of the FURL file.
35 # c.Global.furl_file = u''
35 # c.Global.furl_file = u''
36
36
37 # The working directory for the process. The application will use os.chdir
38 # to change to this directory before starting.
39 # c.Global.working_dir = os.getcwd()
40
37 #-----------------------------------------------------------------------------
41 #-----------------------------------------------------------------------------
38 # MPI configuration
42 # MPI configuration
39 #-----------------------------------------------------------------------------
43 #-----------------------------------------------------------------------------
@@ -256,6 +256,12 b' class AppWithClusterDirArgParseConfigLoader(ArgParseConfigLoader):'
256 '--profile option.',
256 '--profile option.',
257 default=NoConfigDefault,
257 default=NoConfigDefault,
258 metavar='Global.cluster_dir'
258 metavar='Global.cluster_dir'
259 ),
260 self.parser.add_argument('--working-dir',
261 dest='Global.working_dir',type=unicode,
262 help='Set the working dir for the process.',
263 default=NoConfigDefault,
264 metavar='Global.working_dir'
259 )
265 )
260 self.parser.add_argument('--clean-logs',
266 self.parser.add_argument('--clean-logs',
261 dest='Global.clean_logs', action='store_true',
267 dest='Global.clean_logs', action='store_true',
@@ -293,6 +299,7 b' class ApplicationWithClusterDir(Application):'
293 super(ApplicationWithClusterDir, self).create_default_config()
299 super(ApplicationWithClusterDir, self).create_default_config()
294 self.default_config.Global.profile = u'default'
300 self.default_config.Global.profile = u'default'
295 self.default_config.Global.cluster_dir = u''
301 self.default_config.Global.cluster_dir = u''
302 self.default_config.Global.working_dir = os.getcwd()
296 self.default_config.Global.log_to_file = False
303 self.default_config.Global.log_to_file = False
297 self.default_config.Global.clean_logs = False
304 self.default_config.Global.clean_logs = False
298
305
@@ -398,6 +405,16 b' class ApplicationWithClusterDir(Application):'
398 pdir = self.cluster_dir_obj.pid_dir
405 pdir = self.cluster_dir_obj.pid_dir
399 self.pid_dir = config.Global.pid_dir = pdir
406 self.pid_dir = config.Global.pid_dir = pdir
400 self.log.info("Cluster directory set to: %s" % self.cluster_dir)
407 self.log.info("Cluster directory set to: %s" % self.cluster_dir)
408 config.Global.working_dir = unicode(genutils.expand_path(config.Global.working_dir))
409 # Change to the working directory. We do this just before construct
410 # is called so all the components there have the right working dir.
411 self.to_working_dir()
412
413 def to_working_dir(self):
414 wd = self.master_config.Global.working_dir
415 if unicode(wd) != unicode(os.getcwd()):
416 os.chdir(wd)
417 self.log.info("Changing to working dir: %s" % wd)
401
418
402 def start_logging(self):
419 def start_logging(self):
403 # Remove old log files
420 # Remove old log files
@@ -85,7 +85,12 b' class IPClusterCLLoader(ArgParseConfigLoader):'
85 help='Set the cluster dir. This overrides the logic used by the '
85 help='Set the cluster dir. This overrides the logic used by the '
86 '--profile option.',
86 '--profile option.',
87 default=NoConfigDefault,
87 default=NoConfigDefault,
88 metavar='Global.cluster_dir')
88 metavar='Global.cluster_dir'),
89 parent_parser2.add_argument('--working-dir',
90 dest='Global.working_dir',type=unicode,
91 help='Set the working dir for the process.',
92 default=NoConfigDefault,
93 metavar='Global.working_dir')
89 parent_parser2.add_argument('--log-to-file',
94 parent_parser2.add_argument('--log-to-file',
90 action='store_true', dest='Global.log_to_file',
95 action='store_true', dest='Global.log_to_file',
91 default=NoConfigDefault,
96 default=NoConfigDefault,
@@ -242,6 +247,7 b' class IPClusterApp(ApplicationWithClusterDir):'
242 print start_cmd + " ==> " + full_path
247 print start_cmd + " ==> " + full_path
243
248
244 def pre_construct(self):
249 def pre_construct(self):
250 # This is where we cd to the working directory.
245 super(IPClusterApp, self).pre_construct()
251 super(IPClusterApp, self).pre_construct()
246 config = self.master_config
252 config = self.master_config
247 try:
253 try:
@@ -367,8 +373,6 b' class IPClusterApp(ApplicationWithClusterDir):'
367
373
368 # Now write the new pid file AFTER our new forked pid is active.
374 # Now write the new pid file AFTER our new forked pid is active.
369 self.write_pid_file()
375 self.write_pid_file()
370 # cd to the cluster_dir as our working directory.
371 os.chdir(config.Global.cluster_dir)
372 reactor.addSystemEventTrigger('during','shutdown', self.remove_pid_file)
376 reactor.addSystemEventTrigger('during','shutdown', self.remove_pid_file)
373 reactor.run()
377 reactor.run()
374
378
@@ -213,8 +213,7 b' class IPControllerApp(ApplicationWithClusterDir):'
213 del c.Global.secure
213 del c.Global.secure
214
214
215 def construct(self):
215 def construct(self):
216 # I am a little hesitant to put these into InteractiveShell itself.
216 # This is the working dir by now.
217 # But that might be the place for them
218 sys.path.insert(0, '')
217 sys.path.insert(0, '')
219
218
220 self.start_logging()
219 self.start_logging()
@@ -250,8 +249,6 b' class IPControllerApp(ApplicationWithClusterDir):'
250 # controllers to clober each other. But Windows is not cleaning
249 # controllers to clober each other. But Windows is not cleaning
251 # these up properly.
250 # these up properly.
252 self.write_pid_file(overwrite=True)
251 self.write_pid_file(overwrite=True)
253 # cd to the cluster_dir as our working directory.
254 os.chdir(self.master_config.Global.cluster_dir)
255 # Add a trigger to delete the .pid file upon shutting down.
252 # Add a trigger to delete the .pid file upon shutting down.
256 reactor.addSystemEventTrigger('during','shutdown', self.remove_pid_file)
253 reactor.addSystemEventTrigger('during','shutdown', self.remove_pid_file)
257 reactor.run()
254 reactor.run()
@@ -154,8 +154,7 b' class IPEngineApp(ApplicationWithClusterDir):'
154 config.Global.furl_file = try_this
154 config.Global.furl_file = try_this
155
155
156 def construct(self):
156 def construct(self):
157 # I am a little hesitant to put these into InteractiveShell itself.
157 # This is the working dir by now.
158 # But that might be the place for them
159 sys.path.insert(0, '')
158 sys.path.insert(0, '')
160
159
161 self.start_mpi()
160 self.start_mpi()
@@ -224,8 +223,6 b' class IPEngineApp(ApplicationWithClusterDir):'
224 log.msg("Error executing statement: %s" % line)
223 log.msg("Error executing statement: %s" % line)
225
224
226 def start_app(self):
225 def start_app(self):
227 # cd to the cluster_dir as our working directory.
228 os.chdir(self.master_config.Global.cluster_dir)
229 reactor.run()
226 reactor.run()
230
227
231
228
@@ -222,7 +222,11 b' class LocalProcessLauncherProtocol(ProcessProtocol):'
222
222
223
223
224 class LocalProcessLauncher(BaseLauncher):
224 class LocalProcessLauncher(BaseLauncher):
225 """Start and stop an external process in an asynchronous manner."""
225 """Start and stop an external process in an asynchronous manner.
226
227 This will launch the external process with a working directory of
228 ``self.working_dir``.
229 """
226
230
227 # This is used to to construct self.args, which is passed to
231 # This is used to to construct self.args, which is passed to
228 # spawnProcess.
232 # spawnProcess.
@@ -246,7 +250,8 b' class LocalProcessLauncher(BaseLauncher):'
246 self.process_protocol,
250 self.process_protocol,
247 str(self.args[0]), # twisted expects these to be str, not unicode
251 str(self.args[0]), # twisted expects these to be str, not unicode
248 [str(a) for a in self.args], # str expected, not unicode
252 [str(a) for a in self.args], # str expected, not unicode
249 env=os.environ
253 env=os.environ,
254 path=self.working_dir # start in the working_dir
250 )
255 )
251 return self.start_deferred
256 return self.start_deferred
252 else:
257 else:
General Comments 0
You need to be logged in to leave comments. Login now