linux plugin framework

This commit is contained in:
jysperm
2014-10-10 08:41:06 +08:00
parent fb4c7f985c
commit 578ad992ea
3 changed files with 39 additions and 38 deletions

View File

@@ -1,27 +1,28 @@
service = require './service'
monitor = require './monitor'
{pluggable, config} = app
{pluggable} = app
linux = require './linux'
app.view_hook.menu_bar.push
href: '/public/monitor/'
html: '服务器状态'
module.exports =
module.exports = pluggable.createHelpers exports =
name: 'linux'
type: 'service'
service: service
exports.registerHook 'view.layout.menu_bar',
href: '/public/monitor/'
body: '服务器状态'
panel:
widget: service.widget
style:'/style/panel.css'
exports.registerHook 'account.username_filter',
filter: (username, callback) ->
linux.getPasswdMap (passwd_map) ->
callback username in _.values passwd_map
pluggable.account.username_filter.push (account, callback) ->
monitor.loadPasswd (passwd_cache) ->
if req.body.username in _.values(passwd_cache)
return callback false
exports.registerHook 'view.panel.styles',
path: '/plugin/linux/style/panel.css'
callback true
exports.registerHook 'view.panel.widgets',
generator: (req, callback) ->
monitor.run()
exports.registerServiceHook 'enable',
action: (req, callback) ->
exports.registerServiceHook 'disable',
action: (req, callback) ->

View File

@@ -0,0 +1,20 @@
fs = require 'fs'
_ = require 'underscore'
{cache} = app
exports.getPasswdMap = (callback) ->
cache.try 'linux.getPasswdMap',
command: cache.SETEX 120
is_json: true
, (callback) ->
fs.readFile '/etc/passwd', (err, content) ->
result = {}
for line in _.compact(content.toString().split '\n')
[username, password, uid] = line.split ':'
result[uid] = username
callback result
, (passwd_map) ->
callback passwd_map

View File

@@ -56,26 +56,6 @@ exports.loadMemoryInfo = (callback) ->
swap_used_per: swap_used_per
swap_free_per: swap_free_per
exports.loadPasswd = (callback) ->
app.redis.get 'rp:passwd_cache', (err, result) ->
if result
passwd_cache = JSON.parse result
callback passwd_cache
else
fs.readFile '/etc/passwd', (err, content) ->
throw err if err
content = content.toString().split '\n'
passwd_cache = {}
for line in content
if line
[username, password, uid] = line.split ':'
passwd_cache[uid] = username
app.redis.setex 'rp:passwd_cache', 120, JSON.stringify(passwd_cache), ->
callback passwd_cache
exports.getProcessList = (callback) ->
app.redis.get 'rp:process_list', (err, plist) ->
if plist