Server starts up.

This commit is contained in:
SamTV12345 2023-06-25 15:26:34 +02:00
parent aa6323e488
commit 798543fb45
No known key found for this signature in database
GPG key ID: E63EEC7466038043
14 changed files with 121 additions and 4260 deletions

View file

@ -79,32 +79,32 @@ const closeServer = async () => {
};
export const createServer = async () => {
console.log('Report bugs at https://github.com/ether/etherpad-lite/issues');
logger.info('Report bugs at https://github.com/ether/etherpad-lite/issues');
serverName = `Etherpad ${getGitCommit()} (https://etherpad.org)`;
console.log(`Your Etherpad version is ${getEpVersion()} (${getGitCommit()})`);
logger.info(`Your Etherpad version is ${getEpVersion()} (${getGitCommit()})`);
await restartServer();
if (ip.length===0) {
// using Unix socket for connectivity
console.log(`You can access your Etherpad instance using the Unix socket at ${port}`);
logger.info(`You can access your Etherpad instance using the Unix socket at ${port}`);
} else {
console.log(`You can access your Etherpad instance at http://${ip}:${port}/`);
logger.info(`You can access your Etherpad instance at http://${ip}:${port}/`);
}
if (!_.isEmpty(users)) {
console.log(`The plugin admin page is at http://${ip}:${port}/admin/plugins`);
logger.info(`The plugin admin page is at http://${ip}:${port}/admin/plugins`);
} else {
console.warn('Admin username and password not set in settings.json. ' +
logger.info('Admin username and password not set in settings.json. ' +
'To access admin please uncomment and edit "users" in settings.json');
}
const env = process.env.NODE_ENV || 'development';
if (env !== 'production') {
console.warn('Etherpad is running in Development mode. This mode is slower for users and ' +
logger.warn('Etherpad is running in Development mode. This mode is slower for users and ' +
'less secure than production mode. You should set the NODE_ENV environment ' +
'variable to production by using: export NODE_ENV=production');
}

View file

@ -12,12 +12,14 @@ import {getPadId, isReadOnlyId} from "../../db/ReadOnlyManager";
import {UserIndexedModel} from "../../models/UserIndexedModel";
const httpLogger = log4js.getLogger('http');
import {aCallFirst as hookCall} from "../../../static/js/pluginfw/hooks";
deprecationNotices.authFailure = 'use the authnFailure and authzFailure hooks instead';
// Promisified wrapper around hooks.aCallFirst.
const aCallFirst = (hookName, context, pred = null) => new Promise((resolve, reject) => {
// FIXME Why are there 4 arguments but only 3 parameters?
aCallFirst(hookName, context, (err, r) => err != null ? reject(err) : resolve(r));
hookCall(hookName, context, (err, r) => err != null ? reject(err) : resolve(r));
});
const aCallFirst0 =

View file

@ -47,7 +47,7 @@ checkDeprecationStatus('12.17.0', '1.9.0');
import db = require('./db/DB');
import {} from './db/DB'
import express = require('./hooks/express');
import {createServer, server} from './hooks/express';
import hooks = require('../static/js/pluginfw/hooks');
import pluginDefs = require('../static/js/pluginfw/plugin_defs');
import plugins = require('../static/js/pluginfw/plugins');
@ -87,7 +87,7 @@ export const start = async () => {
// Retry. Don't fall through because it might have transitioned to STATE_TRANSITION_FAILED.
return await start();
case State.RUNNING:
return express.server;
return server;
case State.STOPPING:
case State.STOPPED:
case State.EXITING:
@ -152,7 +152,7 @@ export const start = async () => {
logger.debug(`Installed parts:\n${plugins.formatParts()}`);
logger.debug(`Installed server-side hooks:\n${plugins.formatHooks('hooks', false)}`);
await hooks.aCallAll('loadSettings', {settings});
await hooks.aCallAll('createServer');
await hooks.aCallAll(createServer())
} catch (err) {
logger.error('Error occurred while starting Etherpad');
state = State.STATE_TRANSITION_FAILED;
@ -163,9 +163,8 @@ export const start = async () => {
logger.info('Etherpad is running');
state = State.RUNNING;
startDoneGate.resolve();
// Return the HTTP server to make it easier to write tests.
return express.server;
return server;
};
const stopDoneGate = new Gate();
@ -277,7 +276,7 @@ export const exit = async (err = null) => {
logger.info('Waiting for Node.js to exit...');
state = State.WAITING_FOR_EXIT;
/* eslint-enable no-process-exit */
};
if (require.main === module) start();
start()
.then(c=>logger.info("Server started"));

View file

@ -24,7 +24,7 @@ import {promises as fs} from "fs";
import os from 'os';
import path from "path";
import {exportCMD} from "./run_cmd";
import exportCMD from "./run_cmd";
import {soffice} from "./Settings";

View file

@ -28,6 +28,8 @@
*/
import exp from "constants";
// FIXME Is there a better way to enter dynamic package.json path
// @ts-ignore
import packageJSON from '../../../package.json'
import {findEtherpadRoot, makeAbsolute, isSubdir} from './AbsolutePaths';
import deepEqual from 'fast-deep-equal/es6';

View file

@ -1,12 +1,22 @@
'use strict';
import spawn from 'cross-spawn';
import log4js from 'log4js';
import path from 'path';
import {root} from "./Settings";
import {CMDOptions, CMDPromise} from '../models/CMDOptions'
import {root} from './Settings';
import {CustomError} from "./customError";
const logger = log4js.getLogger('runCmd');
import {CustomError} from './customError'
type CMDPromise = {
stdout: Promise<string>,
stderr: Promise<string>,
status: Promise<number>,
signal: Promise<string>,
}
const logLines = (readable, logLineFn) => {
readable.setEncoding('utf8');
// The process won't necessarily write full lines every time -- it might write a part of a line
@ -69,14 +79,23 @@ const logLines = (readable, logLineFn) => {
* - `stderr`: Similar to `stdout` but for stderr.
* - `child`: The ChildProcess object.
*/
export const exportCMD: (args: string[], opts?:CMDOptions)=>void = async (args, opts = {
cwd: undefined,
stdio: undefined,
env: undefined
type RunOpts = {
cwd?: string;
env?: any;
stdio?: any;
detached?: boolean;
uid?: number
}
const run_cmd = (args, opts:RunOpts = {
stdio: undefined
}) => {
logger.debug(`Executing command: ${args.join(' ')}`);
logger.info(`Executing command: ${args.join(' ')}`);
opts = {cwd: root, ...opts};
logger.debug(`cwd: ${opts.cwd}`);
logger.info(`cwd: ${opts.cwd}`);
// Log stdout and stderr by default.
const stdio =
@ -85,24 +104,20 @@ export const exportCMD: (args: string[], opts?:CMDOptions)=>void = async (args,
: opts.stdio === 'string' ? [null, 'string', 'string']
: Array(3).fill(opts.stdio);
const cmdLogger = log4js.getLogger(`runCmd|${args[0]}`);
if (stdio[1] == null && stdio instanceof Array) stdio[1] = (line) => cmdLogger.info(line);
if (stdio[2] == null && stdio instanceof Array) stdio[2] = (line) => cmdLogger.error(line);
if (stdio[1] == null) stdio[1] = (line) => cmdLogger.info(line);
if (stdio[2] == null) stdio[2] = (line) => cmdLogger.error(line);
const stdioLoggers = [];
const stdioSaveString = [];
for (const fd of [1, 2]) {
if (typeof stdio[fd] === 'function') {
stdioLoggers[fd] = stdio[fd];
if (stdio instanceof Array)
stdio[fd] = 'pipe';
stdio[fd] = 'pipe';
} else if (stdio[fd] === 'string') {
stdioSaveString[fd] = true;
if (stdio instanceof Array)
stdio[fd] = 'pipe';
stdio[fd] = 'pipe';
}
}
if (opts.stdio instanceof Array) {
opts.stdio = stdio;
}
opts.stdio = stdio;
// On Windows the PATH environment var might be spelled "Path".
const pathVarName =
@ -123,15 +138,13 @@ export const exportCMD: (args: string[], opts?:CMDOptions)=>void = async (args,
// Create an error object to use in case the process fails. This is done here rather than in the
// process's `exit` handler so that we get a useful stack trace.
const procFailedErr:CustomError = new CustomError({});
const procFailedErr = new CustomError({});
const proc = spawn(args[0], args.slice(1), opts);
const streams = [undefined, proc.stdout, proc.stderr];
let px;
const p = await new Promise<CMDPromise>((resolve, reject) => {
px = {resolve, reject};
});
const p = new Promise<string>((resolve, reject) => { px = {resolve, reject}; });
[, p.stdout, p.stderr] = streams;
p.child = proc;
@ -141,7 +154,6 @@ export const exportCMD: (args: string[], opts?:CMDOptions)=>void = async (args,
if (stdioLoggers[fd] != null) {
logLines(streams[fd], stdioLoggers[fd]);
} else if (stdioSaveString[fd]) {
//FIXME How to solve this?
// @ts-ignore
p[[null, 'stdout', 'stderr'][fd]] = stdioStringPromises[fd] = (async () => {
const chunks = [];
@ -166,3 +178,4 @@ export const exportCMD: (args: string[], opts?:CMDOptions)=>void = async (args,
});
return p;
};
export default run_cmd;