mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-03-28 07:28:57 +08:00
finish memcached plugin
This commit is contained in:
@@ -7,8 +7,6 @@ i18n = require './i18n'
|
||||
config = require './../config'
|
||||
{requestAuthenticate} = require './router/middleware'
|
||||
|
||||
exports.switchButton = []
|
||||
|
||||
exports.get = (name) ->
|
||||
return require path.join(__dirname, "../plugin/#{name}")
|
||||
|
||||
@@ -18,9 +16,6 @@ exports.loadPlugins = (app) ->
|
||||
|
||||
plugin = exports.get name
|
||||
|
||||
if plugin.switch
|
||||
exports.switchButton.push name
|
||||
|
||||
if plugin.action
|
||||
app.use ('/plugin/' + name), plugin.action
|
||||
|
||||
@@ -36,3 +31,6 @@ exports.writeConfig = (path, content, callback) ->
|
||||
|
||||
fs.unlink path, ->
|
||||
callback()
|
||||
|
||||
exports.sudoSu = (account, command) ->
|
||||
return "sudo su #{account.username} -c '#{command}'"
|
||||
@@ -51,21 +51,41 @@ exports.get '/', requestAuthenticate, (req, res) ->
|
||||
|
||||
account.attribute.remaining_time = Math.ceil(billing.calcRemainingTime(account) / 24)
|
||||
|
||||
async.map account.attribute.services, (item, callback) ->
|
||||
p = plugin.get item
|
||||
async.map (p.panel_widgets ? []), (widgetBuilder, callback) ->
|
||||
widgetBuilder account, (html) ->
|
||||
callback null,
|
||||
plugin: p
|
||||
html: html
|
||||
, (err, result) ->
|
||||
callback null, result
|
||||
switch_buttons = []
|
||||
|
||||
async.map account.attribute.services, (service_name, callback) ->
|
||||
service_plugin = plugin.get service_name
|
||||
|
||||
if service_plugin.switch
|
||||
switch_buttons.push service_name
|
||||
|
||||
async.parallel
|
||||
widgets: (callback) ->
|
||||
async.map (service_plugin.panel_widgets ? []), (widgetBuilder, callback) ->
|
||||
widgetBuilder account, (html) ->
|
||||
callback null,
|
||||
plugin: service_plugin
|
||||
html: html
|
||||
, (err, result) ->
|
||||
callback null, result
|
||||
|
||||
switch_status: (callback) ->
|
||||
if service_plugin.switch_status
|
||||
service_plugin.switch_status account, (is_enable) ->
|
||||
account.attribute.plugin[service_name].is_enable = is_enable
|
||||
callback()
|
||||
else
|
||||
callback()
|
||||
|
||||
, callback
|
||||
, (err, result) ->
|
||||
widgets = []
|
||||
|
||||
for item in result
|
||||
widgets = widgets.concat item
|
||||
widgets = widgets.concat item.widgets
|
||||
|
||||
res.render 'panel',
|
||||
switch_buttons: switch_buttons
|
||||
plugin: plugin
|
||||
account: account
|
||||
plans: plans
|
||||
|
||||
@@ -50,7 +50,7 @@ block content
|
||||
|
||||
#service-switch.row
|
||||
header 服务开关
|
||||
for name in plugin.switchButton
|
||||
for name in switch_buttons
|
||||
if account.attribute.plugin[name].is_enable
|
||||
button(data-name= name).btn.btn-danger 关闭 #{t('plugins.' + name + '.name')}
|
||||
else
|
||||
|
||||
@@ -69,7 +69,7 @@ exports.getProcessList = (callback) ->
|
||||
command: result[11]
|
||||
}
|
||||
|
||||
app.redis.setex 'rp:process_list', 10, JSON.stringify(plist), ->
|
||||
app.redis.setex 'rp:process_list', 5, JSON.stringify(plist), ->
|
||||
callback plist
|
||||
|
||||
exports.monitoring = ->
|
||||
|
||||
@@ -9,3 +9,4 @@ module.exports =
|
||||
service: service
|
||||
|
||||
switch: true
|
||||
switch_status: service.switch_status
|
||||
|
||||
@@ -5,9 +5,12 @@ tmp = require 'tmp'
|
||||
fs = require 'fs'
|
||||
|
||||
plugin = require '../../core/plugin'
|
||||
monitor = require '../linux/monitor'
|
||||
|
||||
mAccount = require '../../core/model/account'
|
||||
|
||||
MEMCACHED_FLAGS = '-d -m 16'
|
||||
|
||||
module.exports =
|
||||
enable: (account, callback) ->
|
||||
mAccount.update _id: account._id,
|
||||
@@ -17,13 +20,27 @@ module.exports =
|
||||
callback()
|
||||
|
||||
delete: (account, callback) ->
|
||||
if account.attribute.plugin.memcached.is_enable
|
||||
this.switch account, false, callback
|
||||
else
|
||||
callback()
|
||||
callback()
|
||||
|
||||
switch: (account, is_enable, callback) ->
|
||||
callback()
|
||||
if is_enable
|
||||
app.redis.del 'rp:process_list', =>
|
||||
@switch_status account, (is_act_enable) ->
|
||||
if is_act_enable
|
||||
return callback()
|
||||
|
||||
child_process.exec plugin.sudoSu(account, "memcached #{MEMCACHED_FLAGS} -s ~/memcached.sock"), ->
|
||||
callback()
|
||||
else
|
||||
child_process.exec plugin.sudoSu(account, "pkill -exf -u #{account.username} \"memcached #{MEMCACHED_FLAGS} -s /home/#{account.username}/memcached.sock\""), ->
|
||||
callback()
|
||||
|
||||
switch_status: (account, callback) ->
|
||||
monitor.getProcessList (plist) ->
|
||||
process = _.find plist, (i) ->
|
||||
return i.user == account.username and i.command == "memcached #{MEMCACHED_FLAGS} -s /home/#{account.username}/memcached.sock"
|
||||
|
||||
callback if process then true else false
|
||||
|
||||
preview: (callback) ->
|
||||
jade.renderFile path.join(__dirname, 'view/preview.jade'), {}, (err, html) ->
|
||||
|
||||
Reference in New Issue
Block a user