linux plugin enable and disable

This commit is contained in:
jysperm
2014-10-13 09:46:15 +08:00
parent caa524f3c1
commit 2e38b4b944
4 changed files with 54 additions and 43 deletions

View File

@@ -6,41 +6,6 @@ plugin = require '../../core/pluggable'
monitor = require '../linux/monitor'
module.exports =
enable: (account, callback) ->
child_process.exec "sudo useradd -m -s /bin/bash #{account.username}", (err, stdout, stderr) ->
throw err if err
async.parallel [
(callback) ->
child_process.exec "sudo usermod -G #{account.username} -a www-data", callback
(callback) ->
soft_limit = (account.attribute.resources_limit.storage * 1024 * 0.8).toFixed()
hard_limit = (account.attribute.resources_limit.storage * 1024 * 1.2).toFixed()
soft_inode_limit = (account.attribute.resources_limit.storage * 64 * 0.8).toFixed()
hard_inode_limit = (account.attribute.resources_limit.storage * 64 * 1.2).toFixed()
child_process.exec "sudo setquota -u #{account.username} #{soft_limit} #{hard_limit} #{soft_inode_limit} #{hard_inode_limit} -a", callback
], (err) ->
throw err if err
callback()
delete: (account, callback) ->
async.series [
(callback) ->
child_process.exec "sudo pkill -u #{account.username}", ->
callback()
(callback) ->
child_process.exec "sudo userdel -rf #{account.username}", ->
callback()
(callback) ->
child_process.exec "sudo groupdel #{account.username}", ->
callback()
], (err) ->
throw err if err
callback()
widget: (account, callback) ->
monitor.getProcessList (plist) ->
plist = _.filter plist, (i) ->