Add logging to daemon
This commit is contained in:
parent
5805931c00
commit
ef276a0019
1 changed files with 32 additions and 11 deletions
|
|
@ -2,6 +2,13 @@ import subprocess
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
|
is_flatpak = os.path.exists("/.flatpak-info")
|
||||||
|
log_directory = str(Path.home()) + "/.local/share/goldwarden"
|
||||||
|
if is_flatpak:
|
||||||
|
log_directory = str(Path.home()) + "/.var/app/com.quexten.goldwarden/data/goldwarden"
|
||||||
|
os.makedirs(log_directory, exist_ok=True)
|
||||||
|
|
||||||
BINARY_PATHS = [
|
BINARY_PATHS = [
|
||||||
"/app/bin/goldwarden",
|
"/app/bin/goldwarden",
|
||||||
|
|
@ -163,14 +170,28 @@ def listen_for_pinentry(on_pinentry, on_pin_approval):
|
||||||
pinentry_process.stdin.write("false\n")
|
pinentry_process.stdin.write("false\n")
|
||||||
pinentry_process.stdin.flush()
|
pinentry_process.stdin.flush()
|
||||||
|
|
||||||
# def run_daemon():
|
def run_daemon(token):
|
||||||
# restic_cmd = f"daemonize"
|
#todo replace with stdin
|
||||||
# # print while running
|
daemon_env = os.environ.copy()
|
||||||
# result = subprocess.Popen(restic_cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
daemon_env["GOLDWARDEN_DAEMON_AUTH_TOKEN"] = token
|
||||||
# if result.returncode != 0:
|
|
||||||
# print("Failed err", result.stderr)
|
print("starting goldwarden daemon", BINARY_PATH, token)
|
||||||
# for line in result.stdout:
|
|
||||||
# print(line.decode("utf-8"))
|
# print while running
|
||||||
# result.wait()
|
result = subprocess.Popen([f"{BINARY_PATH}", "daemonize"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, env=daemon_env)
|
||||||
# print("quitting goldwarden daemon")
|
if result.returncode != 0:
|
||||||
# return result.returncode
|
print("Failed err", result.stderr)
|
||||||
|
raise Exception("Failed to start daemon")
|
||||||
|
|
||||||
|
# log stdout and stderr to file
|
||||||
|
with open(f"{log_directory}/daemon.log", "w") as f:
|
||||||
|
f.write(result.stdout.read())
|
||||||
|
f.write(result.stderr.read())
|
||||||
|
|
||||||
|
result.wait()
|
||||||
|
print("quitting goldwarden daemon")
|
||||||
|
return result.returncode
|
||||||
|
|
||||||
|
def run_daemon_background(token):
|
||||||
|
thread = Thread(target=lambda: run_daemon(token))
|
||||||
|
thread.start()
|
||||||
Loading…
Reference in a new issue