reconfigure of bitcoin, linux

This commit is contained in:
jysperm
2014-11-18 12:32:04 +08:00
parent 38b09a191d
commit 822804ea39
3 changed files with 71 additions and 4 deletions

View File

@@ -1,2 +1,25 @@
{utils} = app
{Account} = app.models
bitcoin = require './bitcoin'
module.exports = (callback) ->
callback()
Account.find
'pluggable.bitcoin.bitcoin_deposit_address':
$exists: false
, (err, accounts) ->
async.eachSeries accounts, (account, callback) ->
bitcoin_secret = utils.randomSalt()
console.log "create bitcoin_address for #{account.username}"
bitcoin.genAddress bitcoin_secret, (address) ->
account.update
$set:
'pluggable.bitcoin.bitcoin_deposit_address': address
'pluggable.bitcoin.bitcoin_secret': bitcoin_secret
, callback
, (err) ->
throw err if err
callback()

View File

@@ -46,8 +46,7 @@ exports.registerHook 'account.resources_limit_changed',
exports.registerServiceHook 'enable',
filter: (account, callback) ->
linux.deleteUser account, ->
linux.createUser account, callback
linux.createUser account, callback
exports.registerServiceHook 'disable',
filter: (account, callback) ->

View File

@@ -1,2 +1,47 @@
{async, fs, child_process, _} = app.libs
{Account} = app.models
linux = require './linux'
fs.mkdirSync "#{__dirname}/../.backup/linux", 0o750
module.exports = (callback) ->
callback()
exists_users = _.filter fs.readdirSync('/home'), (file) ->
return fs.statSync("/home/#{file}").isDirectory()
async.series [
(callback) ->
Account.find
'billing.services': 'linux'
, (err, accounts) ->
async.eachSeries accounts, (account, callback) ->
if account.username in exists_users
linux.setResourceLimit account, callback
else
console.log "created linux user for #{account.username}"
linux.createUser account, ->
linux.setResourceLimit account, callback
, callback
(callback) ->
linux.getPasswdMap (passwd_map) ->
async.eachSeries exists_users, (user, callback) ->
if passwd_map[user]
return callback
console.log "removed /home/#{user}"
async.series [
(callback) ->
child_process.exec "sudo mv /home/#{user} #{__dirname}/../.backup/linux/#{user}-#{utils.randomString(5)}", callback
(callback) ->
child_process.exec "sudo rm -r #{user}", callback
], callback
, callback
], (err) ->
throw err if err
callback()