Improve daemon stopping error handling

This commit is contained in:
Arinerron 2018-05-01 23:35:08 -07:00
parent cfb1986ad0
commit 0a7c3aeaab
No known key found for this signature in database
GPG Key ID: 99383627861C62F0
2 changed files with 13 additions and 9 deletions

View File

@ -220,7 +220,7 @@ def error(data, error=None, timestamp=True):
if get_level() <= LEVEL_ERROR: if get_level() <= LEVEL_ERROR:
log('-', data, colors.fg.red, timestamp=timestamp) log('-', data, colors.fg.red, timestamp=timestamp)
if not error is None: if not error is None:
debug('Error details: ' + str(error) + parse_error()) debug('Error: ' + str(error) + parse_error())
# fatal: when the something so bad has happened that the prorgam must stop # fatal: when the something so bad has happened that the prorgam must stop
def fatal(data, timestamp=True): def fatal(data, timestamp=True):

View File

@ -527,15 +527,18 @@ class Onionr:
Shutdown the Onionr daemon Shutdown the Onionr daemon
''' '''
logger.warn('Killing the running daemon') logger.warn('Killing the running daemon...', timestamp = False)
events.event('daemon_stop', onionr = self)
net = NetController(config.get('client')['port'])
try: try:
self.onionrUtils.localCommand('shutdown') events.event('daemon_stop', onionr = self)
except requests.exceptions.ConnectionError: net = NetController(config.get('client')['port'])
pass try:
self.onionrCore.daemonQueueAdd('shutdown') self.onionrUtils.localCommand('shutdown')
net.killTor() except requests.exceptions.ConnectionError:
pass
self.onionrCore.daemonQueueAdd('shutdown')
net.killTor()
except Exception as e:
logger.error('Failed to shutdown daemon.', error = e, timestamp = False)
return return
@ -543,6 +546,7 @@ class Onionr:
''' '''
Displays statistics and exits Displays statistics and exits
''' '''
logger.info('Our pubkey: ' + self.onionrCore._crypto.pubKey) logger.info('Our pubkey: ' + self.onionrCore._crypto.pubKey)
logger.info('Our address: ' + self.get_hostname()) logger.info('Our address: ' + self.get_hostname())
return return