feat: failed services
This commit is contained in:
3 files changed
+13
-80
No files matched your search
-66
@@ -1,66 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
const config = require('./config.json'),
|
||||
ex = require('./execute')
|
||||
|
||||
const services = [
|
||||
'nginx',
|
||||
['bind9', 'DNS'],
|
||||
['isc-dhcp-server', 'DHCP'],
|
||||
['sshd', 'SSH'],
|
||||
['plexmediaserver', 'Plex'],
|
||||
['smbd', 'Samba'],
|
||||
]
|
||||
var spaces = 0
|
||||
|
||||
var promises = []
|
||||
|
||||
for (let service of services) {
|
||||
if (typeof service == 'string') service = [service, service]
|
||||
if (service[1].length > spaces) spaces = service[1].length+1
|
||||
|
||||
promises.push(ex(`systemctl status ${service[0]}`).then(stdout => {
|
||||
return {
|
||||
active: /Active: (.+?) .*; (.*) ago$/gm.exec(stdout).slice(1, 3),
|
||||
memory: (/Memory: (\S+)$/gm.exec(stdout) || []).slice(1, 2),
|
||||
loaded: /Loaded: (.+?) .*?; (.*?); .*$/gm.exec(stdout).slice(1, 3)
|
||||
}
|
||||
}).then(status => {
|
||||
return [service[1], status]
|
||||
}))
|
||||
}
|
||||
|
||||
var out = []
|
||||
|
||||
Promise.all(promises).then(services => {
|
||||
for (let service of services) {
|
||||
var before = '\x1b[32m\u25CF\x1b[0m'
|
||||
if (service[1].active[0] != 'active') before = '\x1b[31m\u25CF'
|
||||
out.push(` ${before} \x1b[1m${
|
||||
service[0] // service name
|
||||
}\x1b[0m:${
|
||||
' '.repeat(spaces - service[0].length) // spacing
|
||||
}${
|
||||
service[1].active[0] != 'active' ? service[1].active[0] : service[1].memory[0] || 'N/A' // status
|
||||
}${
|
||||
service[1].active[0] != 'active' ? ', '+service[1].active[1] : '' // if failed. print
|
||||
} ${
|
||||
service[1].loaded[1] != 'enabled' ? '\x1b[33mdisabled\x1b[0m' : '' // if disabled, print
|
||||
}`)
|
||||
}
|
||||
|
||||
spaces = 0
|
||||
|
||||
for (let service of out) {
|
||||
if (service.length > spaces) spaces = service.length
|
||||
}
|
||||
|
||||
console.log()
|
||||
console.log("Services: ")
|
||||
for (let i in out) {
|
||||
process.stdout.write(out[i])
|
||||
process.stdout.write(' '.repeat(spaces - out[i].length))
|
||||
if ((i+1) % 3 == 0) process.stdout.write('\n')
|
||||
}
|
||||
if ((out.length + 1) % 3 == 0) process.stdout.write('\n')
|
||||
})
|
||||
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
|
||||
failed = os.popen('systemctl --failed').read().split('\n')[1:-7]
|
||||
|
||||
if len(failed) > 0:
|
||||
for service in failed:
|
||||
dot, name, load, active, sub, *description = service.split(' ')
|
||||
|
||||
print('\x1b[31m', dot, name, active, '\x1b[0m', ' '.join(description))
|
||||
|
||||
print()
|
||||
@@ -1,14 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
const config = require('./config.json'),
|
||||
ex = require('./execute')
|
||||
|
||||
ex(`sudo -H -u ${config.pm2_user} bash -c "pm2 jlist"`).then(out => {
|
||||
out = JSON.parse(out)
|
||||
|
||||
console.log()
|
||||
console.log(`PM2 Services:`)
|
||||
for(let service of out){
|
||||
console.log(` \x1b[1m${service.name}\x1b[0m ${service.pm2_env.status != 'online' ? '\x1b[31m' : '\x1b[32m'}${service.pm2_env.status}\x1b[0m ${service.monit.cpu}% ${~~(service.monit.memory / 1024 / 1024)} MB${service.pm2_env.restart_time > 0 ? ` \x1b[33m${service.pm2_env.restart_time} ↺ \x1b[0m` : ''}`)
|
||||
}
|
||||
|
||||
})
|
||||
Reference in new issue
Block a user