actionhero
Version:
actionhero.js is a multi-transport API Server with integrated cluster capabilities and delayed tasks
35 lines (34 loc) • 1.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.clearPidFile = exports.writePidFile = exports.pid = void 0;
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;
}
exports.pid = process.pid;
const path = config_1.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) { }
function writePidFile() {
log_1.log(`pid: ${process.pid}`, "notice");
fs.writeFileSync(path + "/" + title, exports.pid.toString(), "ascii");
}
exports.writePidFile = writePidFile;
function clearPidFile() {
try {
fs.unlinkSync(path + "/" + title);
}
catch (error) {
log_1.log("Unable to remove pidfile", "error", error);
}
}
exports.clearPidFile = clearPidFile;