aboutsummaryrefslogtreecommitdiff
path: root/src/server/ActionUtilities.ts
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2019-12-10 23:40:42 -0500
committerSam Wilkins <samwilkins333@gmail.com>2019-12-10 23:40:42 -0500
commit6665483b80ff6874cf9cc7c9cb3f7e58fcec20ca (patch)
tree68b0059a786769306d0e83246792e719d5617db4 /src/server/ActionUtilities.ts
parent011c777f4109afffd335ba3f447e258e1ad53ddf (diff)
persistance daemon improvements
Diffstat (limited to 'src/server/ActionUtilities.ts')
-rw-r--r--src/server/ActionUtilities.ts13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/server/ActionUtilities.ts b/src/server/ActionUtilities.ts
index bc978c982..2173f4369 100644
--- a/src/server/ActionUtilities.ts
+++ b/src/server/ActionUtilities.ts
@@ -1,12 +1,16 @@
import * as fs from 'fs';
import { ExecOptions } from 'shelljs';
-import { exec } from 'child_process';
+import { exec, spawn } from 'child_process';
import * as path from 'path';
import * as rimraf from "rimraf";
import { yellow, Color } from 'colors';
const projectRoot = path.resolve(__dirname, "../../");
+export function pathFromRoot(relative: string) {
+ return path.resolve(projectRoot, relative);
+}
+
export const command_line = (command: string, fromDirectory?: string) => {
return new Promise<string>((resolve, reject) => {
const options: ExecOptions = {};
@@ -17,6 +21,13 @@ export const command_line = (command: string, fromDirectory?: string) => {
});
};
+export async function spawn_detached_process(command: string, args?: readonly string[]) {
+ const out = path.resolve(projectRoot, `./logs/${command}-${process.pid}-${new Date().toUTCString()}`);
+ const child_out = fs.openSync(out, 'a');
+ const child_error = fs.openSync(out, 'a');
+ spawn(command, args, { detached: true, stdio: ["ignore", child_out, child_error] }).unref();
+}
+
export const read_text_file = (relativePath: string) => {
const target = path.resolve(__dirname, relativePath);
return new Promise<string>((resolve, reject) => {