actionhero
Version:
The reusable, scalable, and quick node.js API server for stateless and stateful applications
33 lines (32 loc) • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.writePidFile = writePidFile;
exports.clearPidFile = clearPidFile;
const fs = require("fs");
const log_1 = require("../../modules/log");
const config_1 = require("./../../modules/config");
const id_1 = require("./id");
function sanitizeId() {
let pidfile = String(id_1.id).trim();
pidfile = pidfile.replace(new RegExp(":", "g"), "-");
pidfile = pidfile.replace(new RegExp(" ", "g"), "_");
return pidfile;
}
const path = config_1.config.general.paths.pid[0]; // it would be silly to have more than one pid
let title = `actionhero-${sanitizeId()}`;
try {
fs.mkdirSync(path);
}
catch (e) { }
function writePidFile() {
(0, log_1.log)(`pid: ${process.pid}`, "notice");
fs.writeFileSync(path + "/" + title, process.pid.toString(), "ascii");
}
function clearPidFile() {
try {
fs.unlinkSync(path + "/" + title);
}
catch (error) {
(0, log_1.log)("Unable to remove pidfile", "error", error);
}
}