[Daemon] Improve logging when another process is using listen port

This commit is contained in:
Calum Lind 2017-02-23 09:31:58 +00:00
parent b2db96e4df
commit b32c5d8247
2 changed files with 15 additions and 7 deletions

View File

@ -11,7 +11,9 @@ from __future__ import print_function, unicode_literals
import os
import sys
from logging import FileHandler, getLogger
from logging import DEBUG, FileHandler, getLogger
from twisted.internet.error import CannotListenError
from deluge.common import run_profiled
from deluge.configmanager import get_config_dir
@ -55,8 +57,8 @@ def start_daemon(skip_start=False):
from deluge.core.daemon import is_daemon_running
pid_file = get_config_dir('deluged.pid')
if is_daemon_running(pid_file):
print('Cannot run multiple daemons using the same config directory.\n'
'If you believe this is an error, you can force a start by deleting: %s' % pid_file)
print('Cannot run multiple daemons with same config directory.\n'
'If you believe this is an error, force starting by deleting: %s' % pid_file)
sys.exit(1)
log = getLogger(__name__)
@ -78,11 +80,18 @@ def start_daemon(skip_start=False):
return daemon
else:
daemon.start()
except CannotListenError as ex:
log.error('Cannot start deluged, listen port in use.\n'
' Check for other running daemons or services using this port: %s:%s',
ex.interface, ex.port)
sys.exit(1)
except Exception as ex:
log.exception(ex)
log.error('Unable to start deluged: %s', ex)
if log.isEnabledFor(DEBUG):
log.exception(ex)
sys.exit(1)
finally:
log.info('Exiting...')
if options.pidfile:
os.remove(options.pidfile)

View File

@ -374,8 +374,7 @@ class RPCServer(component.Component):
try:
reactor.listenSSL(port, self.factory, ServerContextFactory(), interface=hostname)
except Exception as ex:
log.info('Daemon already running or port not available.')
log.error(ex)
log.debug('Daemon already running or port not available.: %s', ex)
raise
def register_object(self, obj, name=None):