Path: blob/master/src/packages/project/init-program.ts
1447 views
/*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";78interface Options {9hubPort: number;10browserPort: number;11hostname: string;12kucalc: boolean;13daemon: boolean;14sshd: boolean;15init: string;16}1718const DEFAULTS: Options = {19hubPort: 0,20browserPort: 0,21// It's important to make the hostname '127.0.0.1' instead of 'localhost',22// and also be consistent with packages/server/projects/control/util.ts23// The distinction can of course matter, e.g,. using '127.0.0.1' causes24// our server to ONLY listen on ipv4, but the client will try 'localhost'25// which on some hosts will resolve to an ipv6 address ::1 first and that26// fails. There's no way to just easily listen on both ipv4 and ipv6 interfaces.27// I noticed that with express if you use localhost you get ipv6 only, and28// with node-http-proxy if you use localhost you get ipv4 only, so things are29// just totally broken. So we explicitly use 127.0.0.1 to force things to30// be consistent.31hostname: "127.0.0.1",32kucalc: false,33daemon: false,34sshd: false,35init: "",36};3738program39.name("cocalc-project")40.usage("[?] [options]")41.option(42"--hub-port <n>",43"TCP server port to listen on (default: 0 = random OS assigned); hub connects to this",44(n) => parseInt(n),45DEFAULTS.hubPort,46)47.option(48"--browser-port <n>",49"HTTP server port to listen on (default: 0 = random OS assigned); browser clients connect to this",50(n) => parseInt(n),51DEFAULTS.browserPort,52)53.option(54"--hostname [string]",55'hostname of interface to bind to (default: "127.0.0.1")',56DEFAULTS.hostname,57)58.option("--kucalc", "Running in the kucalc environment")59.option(60"--sshd",61"Start the SSH daemon (setup script and configuration must be present)",62)63.option(64"--init [string]",65"Runs the given script via bash and redirects output to .log and .err files.",66)67.option("--daemon", "Run as a daemon")68.parse(process.argv);6970function init(): Options {71const opts = program.opts();72for (const key in opts) {73DEFAULTS[key] = opts[key];74}75return DEFAULTS;76}7778const OPTIONS = init();7980export function getOptions() {81return OPTIONS;82}838485