process-list-manager
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "process-list-manager", | ||
"version": "1.0.3", | ||
"description": "", | ||
"scripts": { | ||
"build": "node ./bin/pol.js completion zsh" | ||
}, | ||
"version": "1.0.4", | ||
"description": "Nodejs based init system called process list manager - pol", | ||
"bin": { | ||
@@ -9,0 +6,0 @@ "pol": "./bin/pol.js" |
@@ -1,12 +0,52 @@ | ||
const { spawn } = require('child_process'); | ||
const { spawn, spawnSync } = require('child_process'); | ||
const packageJson = require("../package.json"); | ||
const { ServicesStates } = require('./states'); | ||
const { term } = require('./term'); | ||
const fs = require('fs'); | ||
let log_file; | ||
let LOG_FILE_ROOT = '/var/log/pol'; | ||
let LOG_FILE_PATH = `${LOG_FILE_ROOT}/pol.log`; | ||
const cliRuns = {}; | ||
const execRuns = {}; | ||
// log setup | ||
const TASK_INDENT = ` `; | ||
const log = { | ||
write: console.log, | ||
log: console.log, | ||
warn: console.warn, | ||
err: console.err, | ||
end: () => { } | ||
}; | ||
// log file setup | ||
function cli(_cmd) { | ||
const cmd = [...arguments]; | ||
spawnSync(cmd.shift(), [...cmd], { encoding: 'utf-8', stdio: 'ignore' }); | ||
} | ||
if (!fs.existsSync(LOG_FILE_PATH)) { | ||
try { | ||
fs.accessSync(LOG_FILE_ROOT, fs.constants.R_OK | fs.constants.W_OK | fs.constants.X_OK); | ||
} catch (error) { | ||
log.log(`[${term.fc.red}REQUIRED${term.mc.resetAll}] Please create '/var/log/pol' folder with 'rw' access for the running user!`); | ||
process.exit(1); | ||
} | ||
cli(`touch`, LOG_FILE_PATH); | ||
} | ||
// zsh plugin setup | ||
const polPluginFolder = `${process.env.ZSH}/custom/plugins/pol`; | ||
const polPluginVersion = `${polPluginFolder}/pol.plugin.${packageJson.version}.version`; | ||
if (process.env.ZSH && process.env.ZSH.endsWith('.oh-my-zsh') && !fs.existsSync(polPluginVersion)) { | ||
cli(`mkdir`, `-p`, `${polPluginFolder}`); | ||
cli(`touch`, polPluginVersion); | ||
cli(`cp`, `${__dirname}/../zsh-plugin/pol.plugin.zsh`, `${polPluginFolder}/pol.plugin.zsh`); | ||
cli(`cp`, `${__dirname}/../zsh-plugin/plugin.js`, `${polPluginFolder}/plugin.js`); | ||
log.log(`[${term.fc.green} INFO ${term.mc.resetAll}] .oh-my-zsh custom plugin installed. Please add 'pol' to enabled plugin list in '~/.zshrc' file.`); | ||
} | ||
const log_file = fs.createWriteStream(LOG_FILE_PATH, { flags: 'a' }); | ||
// TODO service state | ||
process.env.TZ = process.env.TZ ? process.env.TZ : fs.readFileSync('/etc/timezone').toString().split('\n')[0]; | ||
const msgToLog = (message, level = 'outlog', service) => { | ||
if (!log_file) log_file = fs.createWriteStream('/var/log/pol/pold.log', { flags: 'a' }); | ||
const log = { | ||
@@ -184,13 +224,4 @@ time: new Date().ISOStrings(), | ||
}); | ||
} | ||
}; | ||
// log setup | ||
const TASK_INDENT = ` `; | ||
const log = { | ||
write: console.log, | ||
log: console.log, | ||
warn: console.warn, | ||
err: console.err, | ||
end: () => { } | ||
}; | ||
const logFile = { | ||
@@ -207,2 +238,4 @@ write: msgToLog, | ||
// Date overrides | ||
@@ -209,0 +242,0 @@ Date.prototype.ISOStrings = function () { |
@@ -155,2 +155,3 @@ const { cliSplitByLine, cliRuns, execRuns, log, logFile, TASK_INDENT } = require('./global'); | ||
promiseAllService.push(new Promise(r => serviceStartResolver = r)); | ||
ServicesStates.init(service.name); | ||
@@ -224,3 +225,2 @@ try { | ||
} | ||
ServicesStates.init(servName); | ||
} | ||
@@ -322,3 +322,2 @@ } | ||
} | ||
log.log(`[${term.fc.red}REQUIRED${term.mc.resetAll}] Please create '/var/log/pol' folder with 'rw' access for the running user!`); | ||
} | ||
@@ -325,0 +324,0 @@ break; |
@@ -6,3 +6,3 @@ | ||
const connections = {}; | ||
const toLog = (msg) => { msgToLog(msg, ' pold ') } | ||
const toLog = (msg) => { msgToLog(msg, 'pol ') } | ||
var server, client; | ||
@@ -14,3 +14,3 @@ | ||
// Our socket | ||
const SOCKETFILE = '/tmp/pold.sock'; | ||
const SOCKETFILE = '/tmp/pol.sock'; | ||
@@ -17,0 +17,0 @@ function serverCreate(socket, onMsg = async (msg, stream) => { }) { |
53160
1242
24