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/init-program.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45// parses command line arguments -- https://github.com/visionmedia/commander.js/6import { program } from "commander";78import { blobstore } from "@cocalc/backend/data";910interface Options {11hubPort: number;12browserPort: number;13hostname: string;14kucalc: boolean;15daemon: boolean;16sshd: boolean;17init: string;18blobstore: typeof blobstore;19}2021const DEFAULTS: Options = {22hubPort: 0,23browserPort: 0,24// It's important to make the hostname '127.0.0.1' instead of 'localhost',25// and also be consistent with packages/server/projects/control/util.ts26// The distinction can of course matter, e.g,. using '127.0.0.1' causes27// our server to ONLY listen on ipv4, but the client will try 'localhost'28// which on some hosts will resolve to an ipv6 address ::1 first and that29// fails. There's no way to just easily listen on both ipv4 and ipv6 interfaces.30// I noticed that with express if you use localhost you get ipv6 only, and31// with node-http-proxy if you use localhost you get ipv4 only, so things are32// just totally broken. So we explicitly use 127.0.0.1 to force things to33// be consistent.34hostname: "127.0.0.1",35kucalc: false,36daemon: false,37sshd: false,38init: "",39blobstore,40};4142program43.name("cocalc-project")44.usage("[?] [options]")45.option(46"--hub-port <n>",47"TCP server port to listen on (default: 0 = random OS assigned); hub connects to this",48(n) => parseInt(n),49DEFAULTS.hubPort,50)51.option(52"--browser-port <n>",53"HTTP server port to listen on (default: 0 = random OS assigned); browser clients connect to this",54(n) => parseInt(n),55DEFAULTS.browserPort,56)57.option(58"--hostname [string]",59'hostname of interface to bind to (default: "127.0.0.1")',60DEFAULTS.hostname,61)62.option("--kucalc", "Running in the kucalc environment")63.option(64"--sshd",65"Start the SSH daemon (setup script and configuration must be present)",66)67.option(68"--init [string]",69"Runs the given script via bash and redirects output to .log and .err files.",70)71.option("--blobstore [string]", "Blobstore type (sqlite or disk)")72.option("--daemon", "Run as a daemon")73.parse(process.argv);7475function init(): Options {76const opts = program.opts();77for (const key in opts) {78DEFAULTS[key] = opts[key];79}80return DEFAULTS;81}8283const OPTIONS = init();8485export function getOptions() {86return OPTIONS;87}888990