services() improved service discovery (linux)

This commit is contained in:
Sebastian Hildebrandt 2021-01-13 19:13:24 +01:00
parent 372236de15
commit 1e3a80e921
4 changed files with 40 additions and 11 deletions

View File

@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page.
| Version | Date | Comment | | Version | Date | Comment |
| -------------- | -------------- | -------- | | -------------- | -------------- | -------- |
| 4.34.7 | 2020-01-13 | `services()` improved service discovery (linux) |
| 4.34.6 | 2020-01-12 | `networkInterfaces()` catch errors | | 4.34.6 | 2020-01-12 | `networkInterfaces()` catch errors |
| 4.34.5 | 2020-01-07 | `networkInterfaceDefault()` fixed CMD popup (windows) | | 4.34.5 | 2020-01-07 | `networkInterfaceDefault()` fixed CMD popup (windows) |
| 4.34.4 | 2020-01-06 | `system()` fixed vitrual catch error | | 4.34.4 | 2020-01-06 | `system()` fixed vitrual catch error |

View File

@ -83,6 +83,11 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr>
<th scope="row">4.34.7</th>
<td>2020-01-13</td>
<td><span class="code">services()</span> improved service discovery linux</td>
</tr>
<tr> <tr>
<th scope="row">4.34.6</th> <th scope="row">4.34.6</th>
<td>2020-01-12</td> <td>2020-01-12</td>

View File

@ -169,7 +169,7 @@
<img class="logo" src="assets/logo.png"> <img class="logo" src="assets/logo.png">
<div class="title">systeminformation</div> <div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span></div> <div class="subtitle"><span id="typed"></span></div>
<div class="version">Current Version: <span id="version">4.34.6</span></div> <div class="version">Current Version: <span id="version">4.34.7</span></div>
<button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button> <button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
</div> </div>
<div class="down"> <div class="down">

View File

@ -124,8 +124,9 @@ function services(srv, callback) {
if (_linux || _freebsd || _openbsd || _netbsd || _darwin) { if (_linux || _freebsd || _openbsd || _netbsd || _darwin) {
if ((_linux || _freebsd || _openbsd || _netbsd) && srvString === '*') { if ((_linux || _freebsd || _openbsd || _netbsd) && srvString === '*') {
try {
srvString = ''; srvString = '';
let tmpsrv = execSync('service --status-all 2> /dev/null').toString().split('\n'); const tmpsrv = execSync('service --status-all 2> /dev/null').toString().split('\n');
for (const s of tmpsrv) { for (const s of tmpsrv) {
const parts = s.split(']'); const parts = s.split(']');
if (parts.length === 2) { if (parts.length === 2) {
@ -134,6 +135,27 @@ function services(srv, callback) {
} }
} }
srvs = srvString.split('|'); srvs = srvString.split('|');
} catch (e) {
try {
const srvStr = execSync('ls /etc/init.d/ -m 2> /dev/null').toString().split('\n').join('');
srvString = '';
if (srvStr) {
const tmpsrv = srvStr.split(',');
for (const s of tmpsrv) {
const name = s.trim();
if (name) {
srvString += (srvString !== '' ? '|' : '') + name;
allSrv.push({ name: name, running: null });
}
}
srvs = srvString.split('|');
}
} catch (f) {
allSrv = [];
srvString = '';
srvs = [];
}
}
} }
let comm = (_darwin) ? 'ps -caxo pcpu,pmem,pid,command' : 'ps -axo pcpu,pmem,pid,command'; let comm = (_darwin) ? 'ps -caxo pcpu,pmem,pid,command' : 'ps -axo pcpu,pmem,pid,command';
if (srvString !== '' && srvs.length > 0) { if (srvString !== '' && srvs.length > 0) {
@ -152,7 +174,7 @@ function services(srv, callback) {
return (e.toLowerCase().indexOf(' ' + srv + ':') !== -1) || (e.toLowerCase().indexOf('/' + srv) !== -1); return (e.toLowerCase().indexOf(' ' + srv + ':') !== -1) || (e.toLowerCase().indexOf('/' + srv) !== -1);
}); });
} }
let singleSrv = allSrv.filter(item => { return item.name === srv; }); // let singleSrv = allSrv.filter(item => { return item.name === srv; });
const pids = []; const pids = [];
for (const p of ps) { for (const p of ps) {
const pid = p.trim().split(' ')[2]; const pid = p.trim().split(' ')[2];
@ -162,7 +184,8 @@ function services(srv, callback) {
} }
result.push({ result.push({
name: srv, name: srv,
running: (allSrv.length && singleSrv.length ? singleSrv[0].running : ps.length > 0), // running: (allSrv.length && singleSrv.length && singleSrv[0].running !== null ? singleSrv[0].running : ps.length > 0),
running: ps.length > 0,
startmode: '', startmode: '',
pids: pids, pids: pids,
pcpu: parseFloat((ps.reduce(function (pv, cv) { pcpu: parseFloat((ps.reduce(function (pv, cv) {