diff --git a/onionr.py b/onionr.py index f72e0c44..c9201186 100755 --- a/onionr.py +++ b/onionr.py @@ -31,6 +31,7 @@ class Onionr: In general, external programs and plugins should not use this class. ''' + self.runningDaemon = False if os.path.exists('dev-enabled'): print('DEVELOPMENT MODE ENABLED (THIS IS LESS SECURE!)') self._developmentMode = True @@ -106,12 +107,17 @@ class Onionr: shutil.rmtree('data/') return def daemon(self): + ''' Start the Onionr communication daemon + ''' if not os.environ.get("WERKZEUG_RUN_MAIN") == "true": subprocess.Popen(["./communicator.py", "run"]) print('Started communicator') api.API(self.config, self.debug) return def killDaemon(self): + if self.runningDaemon == False: + onionrUtils.printErr('No known daemon is running') + sys.exit(1) return def showStats(self): return diff --git a/onionrutils.py b/onionrutils.py index d813575f..49e98e1c 100644 --- a/onionrutils.py +++ b/onionrutils.py @@ -14,10 +14,12 @@ along with this program. If not, see . ''' # Misc functions that do not fit in the main api, but are useful -import getpass +import getpass, sys class OnionrUtils(): def __init__(self): return + def printErr(self, text='an error occured'): + sys.stderr.write(text + '\n') def getPassword(self, message='Enter password: '): # Get a password safely with confirmation and return it while True: