Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions fileglancer/apps/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,17 +703,22 @@ def _run_as_user(username: str, request: dict) -> dict:
else:
logger.debug(
f"Spawning worker action={action} as current user "
f"(euid={os.geteuid()}, not root — no identity switch)"
f"(euid={os.geteuid()})"
)

result = subprocess.run(
[sys.executable, "-m", "fileglancer.apps.worker"],
input=json.dumps(request).encode(),
capture_output=True,
env={**os.environ, "HOME": pw.pw_dir},
env={**os.environ, "HOME": pw.pw_dir, "FGC_LOG_LEVEL": get_settings().log_level},
**identity_kwargs,
)

# Forward worker stderr (contains cluster_api and worker logs)
if result.stderr:
for line in result.stderr.decode().rstrip().splitlines():
logger.debug(f"[worker:{action}] {line}")

if result.stdout:
try:
response = json.loads(result.stdout)
Expand Down Expand Up @@ -1448,7 +1453,7 @@ def get_job_file_paths(db_job: db.JobDB) -> dict[str, dict]:
return files


async def get_job_file_content(job_id: int, username: str, file_type: str) -> Optional[str]:
def get_job_file_content(job_id: int, username: str, file_type: str) -> Optional[str]:
"""Read the content of a job file (script, stdout, or stderr).

All job files live in the job's work directory:
Expand Down
12 changes: 12 additions & 0 deletions fileglancer/apps/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,20 @@ async def _read_manifest(request: dict) -> dict:


def main():
import logging
import pwd as _pwd

# Configure cluster_api logging so debug output reaches the parent
# process via stderr. The parent captures stderr separately.
log_level = os.environ.get("FGC_LOG_LEVEL", "INFO").upper()
handler = logging.StreamHandler(sys.stderr)
handler.setFormatter(logging.Formatter(
"%(levelname)s | %(name)s:%(funcName)s:%(lineno)d - %(message)s"
))
cluster_logger = logging.getLogger("cluster_api")
cluster_logger.addHandler(handler)
cluster_logger.setLevel(log_level)

request = json.loads(sys.stdin.buffer.read())
action = request.get("action")

Expand Down
2 changes: 1 addition & 1 deletion fileglancer/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1850,7 +1850,7 @@ async def get_job_file(job_id: int,
raise HTTPException(status_code=400, detail="file_type must be script, stdout, or stderr")
try:
with _get_user_context(username):
content = await apps_module.get_job_file_content(job_id, username, file_type)
content = apps_module.get_job_file_content(job_id, username, file_type)
if content is None:
raise HTTPException(status_code=404, detail=f"File not found: {file_type}")
return PlainTextResponse(content)
Expand Down
Loading
Loading