mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-15 07:34:27 -04:00
add daemonize flag to archivebox server
This commit is contained in:
parent
035a14b6ea
commit
32167de936
2 changed files with 21 additions and 14 deletions
|
@ -58,6 +58,11 @@ def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='Run archivebox manage createsuperuser before starting the server',
|
help='Run archivebox manage createsuperuser before starting the server',
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--daemonize',
|
||||||
|
action='store_true',
|
||||||
|
help='Run the server in the background as a daemon',
|
||||||
|
)
|
||||||
command = parser.parse_args(args or ())
|
command = parser.parse_args(args or ())
|
||||||
reject_stdin(__command__, stdin)
|
reject_stdin(__command__, stdin)
|
||||||
|
|
||||||
|
@ -68,6 +73,7 @@ def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional
|
||||||
init=command.init,
|
init=command.init,
|
||||||
quick_init=command.quick_init,
|
quick_init=command.quick_init,
|
||||||
createsuperuser=command.createsuperuser,
|
createsuperuser=command.createsuperuser,
|
||||||
|
daemonize=command.daemonize,
|
||||||
out_dir=Path(pwd) if pwd else DATA_DIR,
|
out_dir=Path(pwd) if pwd else DATA_DIR,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -266,8 +266,8 @@ def stop_worker(supervisor, daemon_name):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def start_server_workers(host='0.0.0.0', port='8000'):
|
def start_server_workers(host='0.0.0.0', port='8000', daemonize=False):
|
||||||
supervisor = get_or_create_supervisord_process(daemonize=False)
|
supervisor = get_or_create_supervisord_process(daemonize=daemonize)
|
||||||
|
|
||||||
bg_workers = [
|
bg_workers = [
|
||||||
{
|
{
|
||||||
|
@ -303,18 +303,19 @@ def start_server_workers(host='0.0.0.0', port='8000'):
|
||||||
start_worker(supervisor, worker)
|
start_worker(supervisor, worker)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
try:
|
if not daemonize:
|
||||||
watch_worker(supervisor, "worker_daphne")
|
try:
|
||||||
except KeyboardInterrupt:
|
watch_worker(supervisor, "worker_daphne")
|
||||||
print("\n[🛑] Got Ctrl+C, stopping gracefully...")
|
except KeyboardInterrupt:
|
||||||
except SystemExit:
|
print("\n[🛑] Got Ctrl+C, stopping gracefully...")
|
||||||
pass
|
except SystemExit:
|
||||||
except BaseException as e:
|
pass
|
||||||
print(f"\n[🛑] Got {e.__class__.__name__} exception, stopping web server gracefully...")
|
except BaseException as e:
|
||||||
raise
|
print(f"\n[🛑] Got {e.__class__.__name__} exception, stopping web server gracefully...")
|
||||||
finally:
|
raise
|
||||||
stop_worker(supervisor, "worker_daphne")
|
finally:
|
||||||
time.sleep(0.5)
|
stop_worker(supervisor, "worker_daphne")
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
|
||||||
def start_cli_workers(watch=False):
|
def start_cli_workers(watch=False):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue