|
|
@ -13,13 +13,7 @@ import { |
|
|
|
|
|
|
|
|
|
|
|
import { formatSql } from './formatSql'; |
|
|
|
import { formatSql } from './formatSql'; |
|
|
|
import { repeat } from './repeat'; |
|
|
|
import { repeat } from './repeat'; |
|
|
|
import { |
|
|
|
import { date, perr, pout, poutvar, uuid } from './shell'; |
|
|
|
date, |
|
|
|
|
|
|
|
stderr as sherr, |
|
|
|
|
|
|
|
stdout as shout, |
|
|
|
|
|
|
|
stdoutVar as shvar, |
|
|
|
|
|
|
|
uuid, |
|
|
|
|
|
|
|
} from './shell'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Notes: |
|
|
|
* Notes: |
|
|
@ -37,7 +31,7 @@ class Access extends EventEmitter { |
|
|
|
(args: { options: AccessStartOptions; ps: ChildProcess }) => void |
|
|
|
(args: { options: AccessStartOptions; ps: ChildProcess }) => void |
|
|
|
> = { |
|
|
|
> = { |
|
|
|
connected: ({ options, ps }) => { |
|
|
|
connected: ({ options, ps }) => { |
|
|
|
shvar( |
|
|
|
poutvar( |
|
|
|
options, |
|
|
|
options, |
|
|
|
`Successfully started anvil-access-module daemon (pid=${ps.pid}): `, |
|
|
|
`Successfully started anvil-access-module daemon (pid=${ps.pid}): `, |
|
|
|
); |
|
|
|
); |
|
|
@ -81,7 +75,7 @@ class Access extends EventEmitter { |
|
|
|
...restSpawnOptions, |
|
|
|
...restSpawnOptions, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
shvar(options, `Starting anvil-access-module daemon with: `); |
|
|
|
poutvar(options, `Starting anvil-access-module daemon with: `); |
|
|
|
|
|
|
|
|
|
|
|
const ps = spawn(SERVER_PATHS.usr.sbin['anvil-access-module'].self, args, { |
|
|
|
const ps = spawn(SERVER_PATHS.usr.sbin['anvil-access-module'].self, args, { |
|
|
|
gid, |
|
|
|
gid, |
|
|
@ -91,21 +85,21 @@ class Access extends EventEmitter { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
ps.once('error', (error) => { |
|
|
|
ps.once('error', (error) => { |
|
|
|
sherr( |
|
|
|
perr( |
|
|
|
`anvil-access-module daemon (pid=${ps.pid}) error: ${error.message}`, |
|
|
|
`anvil-access-module daemon (pid=${ps.pid}) error: ${error.message}`, |
|
|
|
error, |
|
|
|
error, |
|
|
|
); |
|
|
|
); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
ps.once('close', (code, signal) => { |
|
|
|
ps.once('close', (code, signal) => { |
|
|
|
shvar( |
|
|
|
poutvar( |
|
|
|
{ code, options, signal }, |
|
|
|
{ code, options, signal }, |
|
|
|
`anvil-access-module daemon (pid=${ps.pid}) closed: `, |
|
|
|
`anvil-access-module daemon (pid=${ps.pid}) closed: `, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
this.emit('inactive', ps.pid); |
|
|
|
this.emit('inactive', ps.pid); |
|
|
|
|
|
|
|
|
|
|
|
shout(`Waiting ${restartInterval} before restarting.`); |
|
|
|
pout(`Waiting ${restartInterval} before restarting.`); |
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
setTimeout(() => { |
|
|
|
this.ps = this.start(options); |
|
|
|
this.ps = this.start(options); |
|
|
@ -113,14 +107,14 @@ class Access extends EventEmitter { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
ps.stderr?.setEncoding('utf-8').on('data', (chunk: string) => { |
|
|
|
ps.stderr?.setEncoding('utf-8').on('data', (chunk: string) => { |
|
|
|
sherr(`anvil-access-module daemon stderr: ${chunk}`); |
|
|
|
perr(`anvil-access-module daemon stderr: ${chunk}`); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
let stdout = ''; |
|
|
|
let stdout = ''; |
|
|
|
|
|
|
|
|
|
|
|
ps.stdout?.setEncoding('utf-8').on('data', (chunk: string) => { |
|
|
|
ps.stdout?.setEncoding('utf-8').on('data', (chunk: string) => { |
|
|
|
const eventless = chunk.replace(/(\n)?event=([^\n]*)\n/g, (...parts) => { |
|
|
|
const eventless = chunk.replace(/(\n)?event=([^\n]*)\n/g, (...parts) => { |
|
|
|
shvar(parts, 'In replacer, args: '); |
|
|
|
poutvar(parts, 'In replacer, args: '); |
|
|
|
|
|
|
|
|
|
|
|
const { 1: n = '', 2: event } = parts; |
|
|
|
const { 1: n = '', 2: event } = parts; |
|
|
|
|
|
|
|
|
|
|
@ -142,7 +136,7 @@ class Access extends EventEmitter { |
|
|
|
if (REP_UUID.test(scriptId)) { |
|
|
|
if (REP_UUID.test(scriptId)) { |
|
|
|
this.emit(scriptId, output); |
|
|
|
this.emit(scriptId, output); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
shout(`Access stdout: ${stdout}`); |
|
|
|
pout(`Access stdout: ${stdout}`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
stdout = stdout.substring(nindex + 1); |
|
|
|
stdout = stdout.substring(nindex + 1); |
|
|
@ -184,13 +178,13 @@ class Access extends EventEmitter { |
|
|
|
return reject(`Failed to parse line ${scriptId}; got [${data}]`); |
|
|
|
return reject(`Failed to parse line ${scriptId}; got [${data}]`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
shvar({ result }, `Access interact ${scriptId} returns: `); |
|
|
|
poutvar({ result }, `Access interact ${scriptId} returns: `); |
|
|
|
|
|
|
|
|
|
|
|
return resolve(result); |
|
|
|
return resolve(result); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
shvar({ script }, 'Access interact: '); |
|
|
|
poutvar({ script }, 'Access interact: '); |
|
|
|
|
|
|
|
|
|
|
|
stdin?.write(script); |
|
|
|
stdin?.write(script); |
|
|
|
|
|
|
|
|
|
|
@ -301,9 +295,9 @@ const refreshTimestamp = () => { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
result = date('--rfc-3339', 'ns').trim(); |
|
|
|
result = date('--rfc-3339', 'ns').trim(); |
|
|
|
} catch (shError) { |
|
|
|
} catch (error) { |
|
|
|
throw new Error( |
|
|
|
throw new Error( |
|
|
|
`Failed to get timestamp for database use; CAUSE: ${shError}`, |
|
|
|
`Failed to get timestamp for database use; CAUSE: ${error}`, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -326,7 +320,7 @@ const getData = async <T>(...keys: string[]) => { |
|
|
|
sub_results: [data], |
|
|
|
sub_results: [data], |
|
|
|
} = await access.interact<{ sub_results: [T] }>('x', chain); |
|
|
|
} = await access.interact<{ sub_results: [T] }>('x', chain); |
|
|
|
|
|
|
|
|
|
|
|
shvar(data, `${chain} data: `); |
|
|
|
poutvar(data, `${chain} data: `); |
|
|
|
|
|
|
|
|
|
|
|
return data; |
|
|
|
return data; |
|
|
|
}; |
|
|
|
}; |
|
|
@ -344,7 +338,7 @@ const mutateData = async <T>(args: { |
|
|
|
sub_results: [data], |
|
|
|
sub_results: [data], |
|
|
|
} = await access.interact<{ sub_results: [T] }>('x', chain, operator, value); |
|
|
|
} = await access.interact<{ sub_results: [T] }>('x', chain, operator, value); |
|
|
|
|
|
|
|
|
|
|
|
shvar(data, `${chain} data: `); |
|
|
|
poutvar(data, `${chain} data: `); |
|
|
|
|
|
|
|
|
|
|
|
return data; |
|
|
|
return data; |
|
|
|
}; |
|
|
|
}; |
|
|
@ -391,7 +385,7 @@ const getLocalHostName = () => { |
|
|
|
throw new Error(`Failed to get local host name; CAUSE: ${subError}`); |
|
|
|
throw new Error(`Failed to get local host name; CAUSE: ${subError}`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
shout(`localHostName=${result}`); |
|
|
|
pout(`localHostName=${result}`); |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return result; |
|
|
|
}; |
|
|
|
}; |
|
|
@ -407,7 +401,7 @@ const getLocalHostUuid = () => { |
|
|
|
throw new Error(`Failed to get local host UUID; CAUSE: ${subError}`); |
|
|
|
throw new Error(`Failed to get local host UUID; CAUSE: ${subError}`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
shout(`localHostUUID=[${result}]`); |
|
|
|
pout(`localHostUUID=[${result}]`); |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return result; |
|
|
|
}; |
|
|
|
}; |
|
|
@ -498,7 +492,7 @@ const getVncinfo = async (serverUuid: string): Promise<ServerDetailVncInfo> => { |
|
|
|
protocol, |
|
|
|
protocol, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
shvar(result, `VNC info for server [${serverUuid}]: `); |
|
|
|
poutvar(result, `VNC info for server [${serverUuid}]: `); |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return result; |
|
|
|
}; |
|
|
|
}; |
|
|
|