From 4510dbfd825399a5fe359a6d3a8f6eeccd995129 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 27 Jan 2018 02:43:36 -0600 Subject: [PATCH] tor now exits properly on STOP command --- onionr/netcontroller.py | 19 ++++++++++++++++++- onionr/onionr.py | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/onionr/netcontroller.py b/onionr/netcontroller.py index 88117d8d..a2aa905d 100644 --- a/onionr/netcontroller.py +++ b/onionr/netcontroller.py @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' -import subprocess, os, random, sys, logger, time +import subprocess, os, random, sys, logger, time, signal class NetController: '''NetController This class handles hidden service setup on Tor and I2P @@ -27,6 +27,7 @@ class NetController: self.readyState = False self.socksPort = random.randint(1024, 65535) self.hsPort = hsPort + self._torInstnace = '' self.myID = '' ''' if os.path.exists(self.torConfigLocation): @@ -66,4 +67,20 @@ HiddenServicePort 80 127.0.0.1:''' + str(self.hsPort) + ''' myID = open('data/hs/hostname', 'r') self.myID = myID.read() myID.close() + torPidFile = open('data/torPid.txt', 'w') + torPidFile.write(str(tor.pid)) + torPidFile.close() return + def killTor(self): + try: + pid = open('data/torPid.txt', 'r') + pidN = pid.read() + pid.close() + except FileNotFoundError: + return + try: + int(pidN) + except: + return + os.kill(int(pidN), signal.SIGTERM) + os.remove('data/torPid.txt') \ No newline at end of file diff --git a/onionr/onionr.py b/onionr/onionr.py index 30fbc298..e6376602 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -134,11 +134,13 @@ class Onionr: def killDaemon(self): '''Shutdown the Onionr Daemon''' logger.warn('Killing the running daemon') + net = NetController(self.config['CLIENT']['PORT']) try: self.onionrUtils.localCommand('shutdown') except requests.exceptions.ConnectionError: pass self.onionrCore.daemonQueueAdd('shutdown') + net.killTor() return def showStats(self): '''Display statistics and exit'''