catch sigterm properly
parent
75c8abd9e0
commit
d6eabe9f12
|
@ -95,7 +95,7 @@ class OnionrCommunicatorDaemon:
|
||||||
peerPoolTimer = OnionrCommunicatorTimers(self, self.getOnlinePeers, 60, maxThreads=1)
|
peerPoolTimer = OnionrCommunicatorTimers(self, self.getOnlinePeers, 60, maxThreads=1)
|
||||||
OnionrCommunicatorTimers(self, self.runCheck, 1)
|
OnionrCommunicatorTimers(self, self.runCheck, 1)
|
||||||
OnionrCommunicatorTimers(self, self.lookupBlocks, self._core.config.get('timers.lookupBlocks'), requiresPeer=True, maxThreads=1)
|
OnionrCommunicatorTimers(self, self.lookupBlocks, self._core.config.get('timers.lookupBlocks'), requiresPeer=True, maxThreads=1)
|
||||||
OnionrCommunicatorTimers(self, self.getBlocks, self._core.config.get('timers.getBlocks'), requiresPeer=True)
|
OnionrCommunicatorTimers(self, self.getBlocks, self._core.config.get('timers.getBlocks'), requiresPeer=True, maxThreads=2)
|
||||||
OnionrCommunicatorTimers(self, self.clearOfflinePeer, 58)
|
OnionrCommunicatorTimers(self, self.clearOfflinePeer, 58)
|
||||||
OnionrCommunicatorTimers(self, self.daemonTools.cleanOldBlocks, 65)
|
OnionrCommunicatorTimers(self, self.daemonTools.cleanOldBlocks, 65)
|
||||||
OnionrCommunicatorTimers(self, self.lookupAdders, 60, requiresPeer=True)
|
OnionrCommunicatorTimers(self, self.lookupAdders, 60, requiresPeer=True)
|
||||||
|
|
|
@ -25,7 +25,7 @@ if sys.version_info[0] == 2 or sys.version_info[1] < 5:
|
||||||
print('Error, Onionr requires Python 3.5+')
|
print('Error, Onionr requires Python 3.5+')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
import os, base64, random, getpass, shutil, subprocess, requests, time, platform, datetime, re, json, getpass, sqlite3
|
import os, base64, random, getpass, shutil, subprocess, requests, time, platform, datetime, re, json, getpass, sqlite3
|
||||||
import webbrowser, uuid
|
import webbrowser, uuid, signal
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import api, core, config, logger, onionrplugins as plugins, onionrevents as events
|
import api, core, config, logger, onionrplugins as plugins, onionrevents as events
|
||||||
import onionrutils
|
import onionrutils
|
||||||
|
@ -51,6 +51,7 @@ class Onionr:
|
||||||
In general, external programs and plugins should not use this class.
|
In general, external programs and plugins should not use this class.
|
||||||
'''
|
'''
|
||||||
self.userRunDir = os.getcwd() # Directory user runs the program from
|
self.userRunDir = os.getcwd() # Directory user runs the program from
|
||||||
|
self.killed = False
|
||||||
try:
|
try:
|
||||||
os.chdir(sys.path[0])
|
os.chdir(sys.path[0])
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
@ -73,6 +74,8 @@ class Onionr:
|
||||||
self.clientAPIInst = '' # Client http api instance
|
self.clientAPIInst = '' # Client http api instance
|
||||||
self.publicAPIInst = '' # Public http api instance
|
self.publicAPIInst = '' # Public http api instance
|
||||||
|
|
||||||
|
signal.signal(signal.SIGTERM, self.exitSigterm)
|
||||||
|
|
||||||
# Handle commands
|
# Handle commands
|
||||||
|
|
||||||
self.debug = False # Whole application debugging
|
self.debug = False # Whole application debugging
|
||||||
|
@ -253,6 +256,9 @@ class Onionr:
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def exitSigterm(self, signum, frame):
|
||||||
|
self.killed = True
|
||||||
|
|
||||||
'''
|
'''
|
||||||
THIS SECTION HANDLES THE COMMANDS
|
THIS SECTION HANDLES THE COMMANDS
|
||||||
'''
|
'''
|
||||||
|
@ -748,17 +754,20 @@ class Onionr:
|
||||||
events.event('daemon_start', onionr = self)
|
events.event('daemon_start', onionr = self)
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
time.sleep(5)
|
time.sleep(3)
|
||||||
|
|
||||||
# Break if communicator process ends, so we don't have left over processes
|
# Break if communicator process ends, so we don't have left over processes
|
||||||
if communicatorProc.poll() is not None:
|
if communicatorProc.poll() is not None:
|
||||||
break
|
break
|
||||||
|
if self.killed:
|
||||||
|
break # Break out if sigterm for clean exit
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
self.onionrCore.daemonQueueAdd('shutdown')
|
self.onionrCore.daemonQueueAdd('shutdown')
|
||||||
self.onionrUtils.localCommand('shutdown')
|
self.onionrUtils.localCommand('shutdown')
|
||||||
|
net.killTor()
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
self.deleteRunFiles()
|
self.deleteRunFiles()
|
||||||
net.killTor()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def killDaemon(self):
|
def killDaemon(self):
|
||||||
|
|
Loading…
Reference in New Issue