Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/project/info-json.ts
Views: 687
/*1Responsible for creating the info.json file that's in the2temporary store (e.g., ~/.smc) for the project. It is used3by various scripts and programs to get basic information4about the project.5*/67import { writeFile } from "node:fs/promises";8import { networkInterfaces } from "node:os";910import basePath from "@cocalc/backend/base-path";11import { infoJson, project_id, username } from "./data";12import { getOptions } from "./init-program";13import { getLogger } from "./logger";1415let INFO: {16project_id: string;17location: { host: string; username: string };18base_path: string;19base_url: string; // backward compat20};2122export { INFO };2324export default async function init() {25const winston = getLogger("info-json init");26winston.info("initializing the info.json file...");27let host: string;28if (process.env.HOST != null) {29host = process.env.HOST;30} else if (getOptions().kucalc) {31// what we want for the Google Compute engine deployment32// earlier, there was eth0, but newer Ubuntu's on GCP have ens433const nics = networkInterfaces();34const mynic = nics.eth0 ?? nics.ens4;35host = mynic?.[0].address ?? "127.0.0.1";36} else {37// for a single machine (e.g., cocalc-docker)38host = "127.0.0.1";39}40INFO = {41project_id,42location: { host, username },43base_path: basePath,44base_url: basePath, // for backwards compat userspace code45};46await writeFile(infoJson, JSON.stringify(INFO));47winston.info(`Successfully wrote "${infoJson}"`);48}495051