+ added basic dev guide
* fixes #22 * When restarting from cli, always output to previous process' terminal
This commit is contained in:
parent
f4e37bbf4e
commit
76f1d164e7
@ -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
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user