network-performance-monitor
Version:
A comprehensive network performance monitoring tool that continuously tests and tracks your network's performance over time
61 lines (60 loc) • 1.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PidFile = void 0;
var fs = require("fs");
var path = require("path");
var config_1 = require("./config");
var PidFile = /** @class */ (function () {
function PidFile() {
this.ensureDirectoryExists();
this.pidPath = path.join(config_1.config.pid.directory, config_1.config.pid.filename);
}
PidFile.prototype.ensureDirectoryExists = function () {
if (!fs.existsSync(config_1.config.pid.directory)) {
fs.mkdirSync(config_1.config.pid.directory, { recursive: true });
}
};
PidFile.prototype.write = function () {
var pid = process.pid;
fs.writeFileSync(this.pidPath, pid.toString());
};
PidFile.prototype.read = function () {
try {
var pidStr = fs.readFileSync(this.pidPath, 'utf-8');
return parseInt(pidStr, 10);
}
catch (error) {
return null;
}
};
PidFile.prototype.remove = function () {
try {
fs.unlinkSync(this.pidPath);
}
catch (error) {
// Ignore error if file doesn't exist
}
};
PidFile.prototype.isProcessRunning = function (pid) {
try {
// Send signal 0 to check if process exists
process.kill(pid, 0);
return true;
}
catch (error) {
return false;
}
};
PidFile.prototype.isDaemonRunning = function () {
var pid = this.read();
if (pid === null) {
return false;
}
return this.isProcessRunning(pid);
};
PidFile.prototype.exists = function () {
return fs.existsSync(this.pidPath);
};
return PidFile;
}());
exports.PidFile = PidFile;