Show More
@@ -414,7 +414,7 b' class ApplicationWithClusterDir(Application):' | |||
|
414 | 414 | open_log_file = sys.stdout |
|
415 | 415 | log.startLogging(open_log_file) |
|
416 | 416 | |
|
417 | def write_pid_file(self): | |
|
417 | def write_pid_file(self, overwrite=False): | |
|
418 | 418 | """Create a .pid file in the pid_dir with my pid. |
|
419 | 419 | |
|
420 | 420 | This must be called after pre_construct, which sets `self.pid_dir`. |
@@ -423,9 +423,11 b' class ApplicationWithClusterDir(Application):' | |||
|
423 | 423 | pid_file = os.path.join(self.pid_dir, self.name + '.pid') |
|
424 | 424 | if os.path.isfile(pid_file): |
|
425 | 425 | pid = self.get_pid_from_file() |
|
426 | raise PIDFileError( | |
|
427 | 'The pid file [%s] already exists. \nThis could mean that this ' | |
|
428 | 'server is already running with [pid=%s].' % (pid_file, pid)) | |
|
426 | if not overwrite: | |
|
427 | raise PIDFileError( | |
|
428 | 'The pid file [%s] already exists. \nThis could mean that this ' | |
|
429 | 'server is already running with [pid=%s].' % (pid_file, pid) | |
|
430 | ) | |
|
429 | 431 | with open(pid_file, 'w') as f: |
|
430 | 432 | self.log.info("Creating pid file: %s" % pid_file) |
|
431 | 433 | f.write(repr(os.getpid())+'\n') |
@@ -442,7 +444,8 b' class ApplicationWithClusterDir(Application):' | |||
|
442 | 444 | self.log.info("Removing pid file: %s" % pid_file) |
|
443 | 445 | os.remove(pid_file) |
|
444 | 446 | except: |
|
445 | pass | |
|
447 | self.log.warn("Error removing the pid file: %s" % pid_file) | |
|
448 | raise | |
|
446 | 449 | |
|
447 | 450 | def get_pid_from_file(self): |
|
448 | 451 | """Get the pid from the pid file. |
@@ -20,7 +20,8 b' import os' | |||
|
20 | 20 | import signal |
|
21 | 21 | import sys |
|
22 | 22 | |
|
23 | from twisted.scripts._twistd_unix import daemonize | |
|
23 | if os.name=='posix': | |
|
24 | from twisted.scripts._twistd_unix import daemonize | |
|
24 | 25 | |
|
25 | 26 | from IPython.core import release |
|
26 | 27 | from IPython.external import argparse |
@@ -246,7 +246,7 b' class IPControllerApp(ApplicationWithClusterDir):' | |||
|
246 | 246 | def start_app(self): |
|
247 | 247 | # Start the controller service and set things running |
|
248 | 248 | self.main_service.startService() |
|
249 | self.write_pid_file() | |
|
249 | self.write_pid_file(overwrite=True) | |
|
250 | 250 | reactor.addSystemEventTrigger('during','shutdown', self.remove_pid_file) |
|
251 | 251 | reactor.run() |
|
252 | 252 |
General Comments 0
You need to be logged in to leave comments.
Login now