f
This commit is contained in:
@@ -64,6 +64,22 @@ except Exception:
|
||||
return kwargs
|
||||
|
||||
|
||||
def _determine_service_user(args) -> Optional[str]:
|
||||
user = getattr(args, "service_user", None)
|
||||
if user:
|
||||
user = user.strip()
|
||||
if not user:
|
||||
user = None
|
||||
if (
|
||||
not user
|
||||
and os.name != "nt"
|
||||
and hasattr(os, "geteuid")
|
||||
and os.geteuid() == 0
|
||||
):
|
||||
user = "hydrusnetwork"
|
||||
return user
|
||||
|
||||
|
||||
def find_git_executable() -> Optional[str]:
|
||||
"""Return the git executable path or None if not found."""
|
||||
import shutil as _shutil
|
||||
@@ -867,6 +883,11 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
default="hydrus-client",
|
||||
help="Name for the installed service/scheduled task (default: hydrus-client)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--service-user",
|
||||
default=None,
|
||||
help="When installing a systemd system service as root, run it under this user",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--no-project-venv",
|
||||
action="store_true",
|
||||
@@ -1197,6 +1218,7 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
run_client_script = cand
|
||||
break
|
||||
|
||||
service_user = _determine_service_user(args)
|
||||
if run_client_script and run_client_script.exists():
|
||||
cmd = [
|
||||
str(venv_py),
|
||||
@@ -1207,6 +1229,8 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
"--detached",
|
||||
"--headless",
|
||||
]
|
||||
if service_user:
|
||||
cmd.extend(["--service-user", service_user])
|
||||
logging.info("Installing service via helper: %s", cmd)
|
||||
try:
|
||||
subprocess.run(cmd, cwd=str(dest), check=True)
|
||||
@@ -1223,6 +1247,7 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
venv_py,
|
||||
headless=True,
|
||||
detached=True,
|
||||
service_user=service_user,
|
||||
)
|
||||
if ok:
|
||||
logging.info("Service installed (user-level).")
|
||||
@@ -1559,6 +1584,7 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
)
|
||||
else:
|
||||
if getattr(args, "install_service", False):
|
||||
service_user = _determine_service_user(args)
|
||||
if run_client_script and run_client_script.exists():
|
||||
cmd = [
|
||||
str(venv_py),
|
||||
@@ -1569,6 +1595,8 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
"--detached",
|
||||
"--headless",
|
||||
]
|
||||
if service_user:
|
||||
cmd.extend(["--service-user", service_user])
|
||||
logging.info("Installing service via helper: %s", cmd)
|
||||
try:
|
||||
subprocess.run(cmd, cwd=str(dest), check=True)
|
||||
@@ -1582,7 +1610,8 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
dest,
|
||||
venv_py,
|
||||
headless=True,
|
||||
detached=True
|
||||
detached=True,
|
||||
service_user=service_user
|
||||
)
|
||||
if ok:
|
||||
logging.info("Service installed (user-level).")
|
||||
|
||||
Reference in New Issue
Block a user