diff --git a/docs/dev/setup.md b/docs/dev/setup.md index e1706b72..d0794e75 100644 --- a/docs/dev/setup.md +++ b/docs/dev/setup.md @@ -6,6 +6,8 @@ The Onionr development environment is simple. All one really needs is a supporte There are additional requirements specified in requirements-dev.txt +Developers agree to the CoC and to contribute new code under GPLv3 or later. Developers should stick to PEP8 in most cases, and write unittests or integration tests where possible. + ## Developer Scripts run-onionr-node.py can be used to start a node with specific parameters diff --git a/src/httpapi/miscclientapi/endpoints.py b/src/httpapi/miscclientapi/endpoints.py index 715e8c43..6fbfcade 100644 --- a/src/httpapi/miscclientapi/endpoints.py +++ b/src/httpapi/miscclientapi/endpoints.py @@ -5,6 +5,7 @@ Misc client API endpoints too small to need their own file and that need access import os import subprocess import platform +from sys import stdout as sys_stdout from flask import Response, Blueprint, request, send_from_directory, abort from flask import g @@ -70,6 +71,10 @@ class PrivateEndpoints: def get_pid(): return Response(str(os.getpid())) + @private_endpoints_bp.route('/isatty') + def get_is_atty(): + return Response(str(sys_stdout.isatty()).lower()) + @private_endpoints_bp.route('/hitcount') def get_hit_count(): return Response(str(client_api.publicAPI.hitCount)) diff --git a/src/onionrcommands/daemonlaunch/killdaemon.py b/src/onionrcommands/daemonlaunch/killdaemon.py index dd65fc01..a8f74220 100644 --- a/src/onionrcommands/daemonlaunch/killdaemon.py +++ b/src/onionrcommands/daemonlaunch/killdaemon.py @@ -31,7 +31,7 @@ import config def kill_daemon(): """Shutdown the Onionr daemon (communicator).""" config.reload() - logger.warn('Stopping the running daemon...', timestamp=False, + logger.warn('Stopping the running daemon, if one exists...', timestamp=False, terminal=True) # On platforms where we can, fork out to prevent locking diff --git a/src/onionrcommands/restartonionr.py b/src/onionrcommands/restartonionr.py index 692a6b61..2104513e 100644 --- a/src/onionrcommands/restartonionr.py +++ b/src/onionrcommands/restartonionr.py @@ -2,10 +2,13 @@ Command to restart Onionr """ +from threading import local import time import os import subprocess # nosec +from psutil import Process + from etc import onionrvalues from etc import cleanup from onionrutils import localcommand @@ -28,15 +31,23 @@ from . import daemonlaunch along with this program. If not, see . """ - +DEVNULL = subprocess.DEVNULL SCRIPT_NAME = os.path.dirname(os.path.realpath( __file__)) + f'/../../{onionrvalues.SCRIPT_NAME}' def restart(): """Tell the Onionr daemon to restart.""" + logger.info('Restarting Onionr', terminal=True) + daemon_terminal = localcommand.local_command("getpid") + terminal = None + if daemon_terminal: + terminal = Process(int(daemon_terminal)).terminal() + else: + terminal = Process().terminal() + # On platforms where we can, fork out to prevent locking try: pid = os.fork() @@ -55,7 +66,13 @@ def restart(): time.sleep(1) cleanup.delete_run_files() - subprocess.Popen([SCRIPT_NAME, 'start']) + + with open(terminal, 'ab') as term: + subprocess.Popen( + [SCRIPT_NAME, 'start'], + stdout=term, + stdin=term, + stderr=term) restart.onionr_help = 'Gracefully restart Onionr' # type: ignore