mirror of
https://github.com/samschott/maestral.git
synced 2024-10-06 18:37:20 +03:00
added --verbose option to maestral start|restart
--foreground no longer logs to stdout by default
This commit is contained in:
parent
d03d9d37e2
commit
0192c7304c
@ -53,13 +53,13 @@ def pending_link_cli(config_name):
|
||||
'to load Dropbox credentials.')
|
||||
|
||||
|
||||
def start_daemon_subprocess_with_cli_feedback(config_name):
|
||||
def start_daemon_subprocess_with_cli_feedback(config_name, log_to_stdout=False):
|
||||
"""Wrapper around `daemon.start_maestral_daemon_process`
|
||||
with command line feedback."""
|
||||
from maestral.daemon import start_maestral_daemon_process, Start
|
||||
|
||||
click.echo('Starting Maestral...', nl=False)
|
||||
res = start_maestral_daemon_process(config_name)
|
||||
res = start_maestral_daemon_process(config_name, log_to_stdout=log_to_stdout)
|
||||
if res == Start.Ok:
|
||||
click.echo('\rStarting Maestral... ' + OK)
|
||||
else:
|
||||
@ -322,8 +322,10 @@ def gui(config_name):
|
||||
@config_option
|
||||
@click.option('--foreground', '-f', is_flag=True, default=False,
|
||||
help='Starts Maestral in the foreground.')
|
||||
@click.option('--verbose', '-v', is_flag=True, default=False,
|
||||
help='Print log messages to stdout.')
|
||||
@catch_maestral_errors
|
||||
def start(config_name: str, foreground: bool):
|
||||
def start(config_name: str, foreground: bool, verbose: bool):
|
||||
"""Starts the Maestral as a daemon."""
|
||||
|
||||
from maestral.daemon import get_maestral_pid
|
||||
@ -360,11 +362,9 @@ def start(config_name: str, foreground: bool):
|
||||
# start daemon
|
||||
if foreground:
|
||||
from maestral.daemon import run_maestral_daemon
|
||||
from maestral.constants import INVOCATION_ID
|
||||
# don't log to stdout if started from systemd
|
||||
run_maestral_daemon(config_name, run=True, log_to_stdout=not INVOCATION_ID)
|
||||
run_maestral_daemon(config_name, run=True, log_to_stdout=verbose)
|
||||
else:
|
||||
start_daemon_subprocess_with_cli_feedback(config_name)
|
||||
start_daemon_subprocess_with_cli_feedback(config_name, log_to_stdout=verbose)
|
||||
|
||||
|
||||
@main.command(help_priority=2)
|
||||
@ -378,8 +378,10 @@ def stop(config_name: str):
|
||||
@existing_config_option
|
||||
@click.option('--foreground', '-f', is_flag=True, default=False,
|
||||
help='Starts Maestral in the foreground.')
|
||||
@click.option('--verbose', '-v', is_flag=True, default=False,
|
||||
help='Print log messages to stdout.')
|
||||
@click.pass_context
|
||||
def restart(ctx, config_name: str, foreground: bool):
|
||||
def restart(ctx, config_name: str, foreground: bool, verbose: bool):
|
||||
"""Restarts the Maestral daemon."""
|
||||
stop_daemon_with_cli_feedback(config_name)
|
||||
ctx.forward(start)
|
||||
|
@ -247,7 +247,7 @@ def run_maestral_daemon(config_name='maestral', run=True, log_to_stdout=False):
|
||||
lockfile.release()
|
||||
|
||||
|
||||
def start_maestral_daemon_thread(config_name='maestral', run=True):
|
||||
def start_maestral_daemon_thread(config_name='maestral', run=True, log_to_stdout=False):
|
||||
"""
|
||||
Starts the Maestral daemon in a thread (by calling `start_maestral_daemon`).
|
||||
This command will create a new daemon on each run. Take care not to sync the same
|
||||
@ -257,14 +257,14 @@ def start_maestral_daemon_thread(config_name='maestral', run=True):
|
||||
|
||||
:param str config_name: The name of the Maestral configuration to use.
|
||||
:param bool run: If ``True``, start syncing automatically. Defaults to ``True``.
|
||||
:returns: ``True`` if started, ``False`` otherwise.
|
||||
:rtype: bool
|
||||
:param bool log_to_stdout: If ``True``, write logs to stdout. Defaults to ``False``.
|
||||
:returns: ``Start.Ok`` if successful, ``Start.Failed`` otherwise.
|
||||
"""
|
||||
import threading
|
||||
|
||||
t = threading.Thread(
|
||||
target=run_maestral_daemon,
|
||||
args=(config_name, run),
|
||||
args=(config_name, run, log_to_stdout),
|
||||
name=f'maestral-daemon-{config_name}',
|
||||
daemon=True,
|
||||
)
|
||||
@ -278,12 +278,13 @@ def start_maestral_daemon_thread(config_name='maestral', run=True):
|
||||
return _wait_for_startup(config_name, timeout=8)
|
||||
|
||||
|
||||
def start_maestral_daemon_process(config_name='maestral', run=True):
|
||||
def start_maestral_daemon_process(config_name='maestral', run=True, log_to_stdout=False):
|
||||
"""
|
||||
Starts the Maestral daemon as a separate process (by calling `start_maestral_daemon`).
|
||||
|
||||
:param str config_name: The name of the Maestral configuration to use.
|
||||
:param bool run: If ``True``, start syncing automatically. Defaults to ``True``.
|
||||
:param bool log_to_stdout: If ``True``, write logs to stdout. Defaults to ``False``.
|
||||
:returns: ``Start.Ok`` if successful, ``Start.Failed`` otherwise.
|
||||
"""
|
||||
import subprocess
|
||||
@ -292,14 +293,14 @@ def start_maestral_daemon_process(config_name='maestral', run=True):
|
||||
|
||||
STD_IN_OUT = subprocess.DEVNULL
|
||||
|
||||
# use nested Popen and multiprocessing.Process to effectively create double fork
|
||||
# use nested Popen and multiprocessing.Process to effectively create double fork`
|
||||
# see Unix 'double-fork magic'
|
||||
|
||||
def target(cc, r):
|
||||
cc = quote(cc)
|
||||
r = bool(r)
|
||||
subprocess.Popen(
|
||||
[sys.executable, '-c', f'import maestral.daemon; maestral.daemon.run_maestral_daemon("{cc}", {r})'],
|
||||
[sys.executable, '-c', f'import maestral.daemon; maestral.daemon.run_maestral_daemon("{cc}", {r}, {log_to_stdout})'],
|
||||
stdin=STD_IN_OUT, stdout=STD_IN_OUT, stderr=STD_IN_OUT,
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user