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