actionhero
Version:
The reusable, scalable, and quick node.js API server for stateless and stateful applications
34 lines (27 loc) • 844 B
text/typescript
import * as fs from "fs";
import { log } from "../../modules/log";
import { config } from "./../../modules/config";
import { id } from "./id";
function sanitizeId() {
let pidfile = String(id).trim();
pidfile = pidfile.replace(new RegExp(":", "g"), "-");
pidfile = pidfile.replace(new RegExp(" ", "g"), "_");
return pidfile;
}
export const pid = process.pid;
const path = config.general.paths.pid[0]; // it would be silly to have more than one pi
let title = `actionhero-${sanitizeId()}`;
try {
fs.mkdirSync(path);
} catch (e) {}
export function writePidFile() {
log(`pid: ${process.pid}`, "notice");
fs.writeFileSync(path + "/" + title, pid.toString(), "ascii");
}
export function clearPidFile() {
try {
fs.unlinkSync(path + "/" + title);
} catch (error) {
log("Unable to remove pidfile", "error", error);
}
}