diff --git a/coremods/control.py b/coremods/control.py index 78f1c54..ad352ce 100644 --- a/coremods/control.py +++ b/coremods/control.py @@ -24,13 +24,16 @@ def _print_remaining_threads(): log.debug('_shutdown(): Remaining threads: %s', ['%s/%s' % (t.name, t.ident) for t in threading.enumerate()]) def _remove_pid(): - # Remove our pid file. pidfile = "%s.pid" % conf.confname - log.info("Removing PID file %r.", pidfile) - try: - os.remove(pidfile) - except OSError: - log.exception("Failed to remove PID file %r, ignoring..." % pidfile) + if world._should_remove_pid: + # Remove our pid file. + log.info("Removing PID file %r.", pidfile) + try: + os.remove(pidfile) + except OSError: + log.exception("Failed to remove PID file %r, ignoring..." % pidfile) + else: + log.debug('Not removing PID file %s as world._should_remove_pid is False.' % pidfile) def _kill_plugins(irc=None): log.info("Shutting down plugins.") diff --git a/pylink b/pylink index aea3b45..08166fb 100755 --- a/pylink +++ b/pylink @@ -58,6 +58,7 @@ if __name__ == '__main__': if not args.no_pid: with open('%s.pid' % conf.confname, 'w') as f: f.write(str(os.getpid())) + world._should_remove_pid = True # Import plugins first globally, because they can listen for events # that happen before the connection phase. diff --git a/world.py b/world.py index 7e81d4e..dd42640 100644 --- a/world.py +++ b/world.py @@ -33,3 +33,6 @@ fallback_hostname = 'pylink.int' # Defines messages to be logged as soon as the log system is set up, for modules like conf that are # initialized before log. This is processed (and then not used again) when the log module loads. log_queue = deque() + +# Determines whether we have a PID file that needs to be removed. +_should_remove_pid = False