CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/project/project.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import daemonizeProcess from "daemonize-process";
7
8
import { init as initBugCounter } from "./bug-counter";
9
import { init as initClient } from "./client";
10
import initInfoJson from "./info-json";
11
import initKucalc from "./init-kucalc";
12
import { getOptions } from "./init-program";
13
import { cleanup as cleanupEnvironmentVariables } from "./project-setup";
14
import initPublicPaths from "./public-paths";
15
import initServers from "./servers/init";
16
17
import { getLogger } from "./logger";
18
const logger = getLogger("project-main");
19
20
function checkEnvVariables() {
21
const { HOME } = process.env;
22
if (HOME == null) {
23
throw Error("HOME env var must be set");
24
}
25
process.chdir(HOME);
26
27
if (process.env.DATA == null) {
28
throw Error("DATA env var must be set");
29
}
30
// TODO: some code, e.g., smc_pyutil's cc-jupyter script, assumes
31
// that SMC is defined still.
32
process.env.SMC = process.env.DATA;
33
}
34
35
export async function main() {
36
initBugCounter();
37
checkEnvVariables();
38
const options = getOptions();
39
if (options.daemon) {
40
logger.info("daemonize the process");
41
daemonizeProcess();
42
}
43
cleanupEnvironmentVariables();
44
initKucalc(); // must be after cleanupEnvironmentVariables, since this *adds* custom environment variables.
45
logger.info("main init function");
46
logger.info("initialize INFO.json file");
47
await initInfoJson();
48
logger.info("create Client interface");
49
initClient();
50
logger.info("create all the servers...");
51
await initServers();
52
logger.info("create public paths watcher...");
53
initPublicPaths();
54
}
55
56