UNPKG

alks

Version:
44 lines 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleAlksServerStop = void 0; const tslib_1 = require("tslib"); const cli_color_1 = tslib_1.__importDefault(require("cli-color")); const isOsx_1 = require("../isOsx"); const fs_1 = tslib_1.__importDefault(require("fs")); const path_1 = tslib_1.__importDefault(require("path")); const os_1 = tslib_1.__importDefault(require("os")); const PID_FILE = path_1.default.join(os_1.default.tmpdir(), 'alks-metadata-server.pid'); function handleAlksServerStop(_options) { return tslib_1.__awaiter(this, void 0, void 0, function* () { if (!(0, isOsx_1.isOsx)()) { console.error(cli_color_1.default.red('The metadata server is only supported on OSX.')); process.exit(0); } console.error(cli_color_1.default.white('Stopping metadata server..')); try { if (!fs_1.default.existsSync(PID_FILE)) { console.log(cli_color_1.default.white('Metadata server is not running.')); return; } const pid = parseInt(fs_1.default.readFileSync(PID_FILE, 'utf8').trim(), 10); // Check if process exists try { process.kill(pid, 0); // Signal 0 checks if process exists // Process exists, kill it process.kill(pid, 'SIGTERM'); fs_1.default.unlinkSync(PID_FILE); console.log(cli_color_1.default.white('Metadata server stopped.')); } catch (err) { // Process doesn't exist, remove stale PID file fs_1.default.unlinkSync(PID_FILE); console.log(cli_color_1.default.white('Metadata server is not running.')); } } catch (err) { console.error(cli_color_1.default.red('Error stopping metadata server:'), err); } }); } exports.handleAlksServerStop = handleAlksServerStop; //# sourceMappingURL=alks-server-stop.js.map