reconfigure

This commit is contained in:
jysperm
2014-11-18 10:26:32 +08:00
parent 2d45735ec2
commit 6eb7dc6895
17 changed files with 147 additions and 53 deletions

0
.backup/.gitkeep Normal file
View File

View File

@@ -29,25 +29,25 @@ RootPanel 具有良好的设计,高度的可定制性,支持多语言和多
## 从旧版本升级
停止 RootPanel:
# 停止 RootPanel
supervisorctl stop RootPanel
更新源代码:
# 备份数据库
mongodump --db RootPanel --out .backup/db -u rpadmin -p
# 更新源代码
git pull
根据 `/migration/system` 中新增的说明文件,执行相应命令来修改系统设置,如果跨越多个版本需要依次执行。
检查更新日志和 `/sample` 中的默认配置文件,视情况修改配置文件(`config.coffee`), 若修改了配置文件,需要运行以下命令来应用变更。
npm run reconfigure
使用 `mongodbdump` 来备份数据库,然后升级数据库:
检查更新日志和 `/sample` 中的默认配置文件,视情况修改配置文件(`config.coffee`).
# 升级数据库
npm run migrate
启动 RootPanel:
# 应用新的设置
npm run reconfigure
# 启动 RootPanel
supervisorctl start RootPanel
## 技术构成

View File

@@ -132,13 +132,14 @@ app.express.get '/', (req, res) ->
app.express.use harp.mount './core/static'
app.express.listen config.web.listen, ->
app.started = true
unless module.parent
app.express.listen config.web.listen, ->
app.started = true
if fs.existsSync config.web.listen
fs.chmodSync config.web.listen, 0o770
if fs.existsSync config.web.listen
fs.chmodSync config.web.listen, 0o770
app.pluggable.selectHook(null, 'app.started').forEach (hook) ->
hook.action()
app.pluggable.selectHook(null, 'app.started').forEach (hook) ->
hook.action()
app.logger.log "RootPanel start at #{config.web.listen}"
app.logger.log "RootPanel start at #{config.web.listen}"

View File

@@ -1 +1,63 @@
#!/usr/bin/env coffee
require '../app'
{async, fs, _} = app.libs
{config, pluggable} = app
{Account} = app.models
Account.find
'billing.plans.0':
$exists: true
, (err, accounts) ->
async.eachSeries accounts, (account, callback) ->
original_account = account
services = _.flatten _.compact _.map account.billing.plans, (plan) ->
return config.plans[plan]?.services
if _.isEqual account.billing.services, services
return callback()
Account.findByIdAndUpdate account._id,
$set:
'billing.services': services
, (err, account) ->
services = account.billing.services
original_services = original_account.billing.services
async.series [
(callback) ->
async.each _.difference(services, original_services), (service_name, callback) ->
console.log "#{account.username} enabled #{service_name}"
async.each pluggable.selectHook(account, "service.#{service_name}.enable"), (hook, callback) ->
hook.filter account, callback
, callback
, callback
(callback) ->
async.each _.difference(original_services, services), (service_name, callback) ->
console.log "#{account.username} disabled #{service_name}"
async.each pluggable.selectHook(account, "service.#{service_name}.disable"), (hook, callback) ->
hook.filter account, callback
, callback
, callback
], callback
, ->
available_plugins = _.union config.plugin.available_extensions, config.plugin.available_services
async.eachSeries available_plugins, (plugin_name, callback) ->
filename = "#{__dirname}/../plugin/#{plugin_name}/reconfigure.coffee"
unless fs.existsSync filename
return callback()
require(filename) ->
callback()
, ->
console.log 'Reconfigure Finish'
process.exit 0

View File

@@ -119,7 +119,7 @@ exports.joinPlan = (req, account, plan_name, callback) ->
async.each _.difference(account.billing.services, original_account.billing.services), (service_name, callback) ->
async.each pluggable.selectHook(account, "service.#{service_name}.enable"), (hook, callback) ->
hook.filter req, callback
hook.filter account, callback
, callback
, ->
unless _.isEqual original_account.resources_limit, account.resources_limit
@@ -155,7 +155,7 @@ exports.leavePlan = (req, account, plan_name, callback) ->
async.each leaved_services, (service_name, callback) ->
async.each pluggable.selectHook(original_account, "service.#{service_name}.disable"), (hook, callback) ->
hook.filter req, callback
hook.filter account, callback
, callback
, ->
unless _.isEqual original_account.resources_limit, account.resources_limit

View File

@@ -64,9 +64,9 @@ exports.hooks =
service:
'service_name':
# filter: function(req, callback)
# filter: function(account, callback)
enable: []
# filter: function(req, callback)
# filter: function(account, callback)
disable: []
plugin:

View File

@@ -1,14 +1,16 @@
npm install coffee-script -g
## Core
vi /etc/rc.local
npm install coffee-script -g
vi /etc/rc.local
iptables-restore < /etc/iptables.rules
iptables-restore < /etc/iptables.rules
vi /etc/supervisor/conf.d/rpadmin.conf
vi /etc/supervisor/conf.d/rpadmin.conf
[program:RootPanel]
command=node /home/rpadmin/RootPanel/start.js
autorestart=true
user=rpadmin
[program:RootPanel]
command=node /home/rpadmin/RootPanel/start.js
autorestart=true
user=rpadmin
service supervisor restart
service supervisor restart

View File

@@ -0,0 +1,16 @@
## Core
vi /etc/rc.local
ln -s /dev/xvda /dev/root
vi /etc/supervisor/conf.d/rpadmin.conf
[program:RootPanel]
command = coffee /home/rpadmin/RootPanel/app.coffee
directory = /home/rpadmin/RootPanel
autorestart = true
redirect_stderr = true
user = rpadmin
service supervisor restart

View File

@@ -0,0 +1,2 @@
module.exports = (callback) ->
callback()

View File

@@ -45,13 +45,18 @@ exports.registerHook 'account.resources_limit_changed',
linux.setResourceLimit account, callback
exports.registerServiceHook 'enable',
filter: (req, callback) ->
linux.deleteUser req.account, ->
linux.createUser req.account, callback
filter: (account, callback) ->
linux.deleteUser account, ->
linux.createUser account, callback
exports.registerServiceHook 'disable',
filter: (req, callback) ->
linux.deleteUser req.account, callback
filter: (account, callback) ->
linux.deleteUser account, callback
if config.plugins.linux.monitor_cycle
exports.registerHook 'app.started',
action: ->
monitor.run()
app.express.get '/public/monitor', requireAuthenticate, (req, res) ->
async.parallel
@@ -67,6 +72,3 @@ app.express.get '/public/monitor', requireAuthenticate, (req, res) ->
logger.error err if err
exports.render 'monitor', req, result, (html) ->
res.send html
if config.plugins.linux.monitor_cycle
monitor.run()

View File

@@ -0,0 +1,2 @@
module.exports = (callback) ->
callback()

View File

@@ -16,10 +16,6 @@ exports.registerHook 'view.layout.menu_bar',
target: '_blank'
t_body: 'plugins.rpvhost.official_blog'
if config.plugins.rpvhost.green_style
exports.registerHook 'view.layout.styles',
path: '/plugin/rpvhost/style/green.css'
exports.registerHook 'billing.payment_methods',
widget_generator: (req, callback) ->
exports.render 'payment_method', req, {}, callback
@@ -30,6 +26,10 @@ exports.registerHook 'view.pay.display_payment_details',
callback exports.t(req) 'view.payment_details',
order_id: deposit_log.payload.order_id
if config.plugins.rpvhost.green_style
exports.registerHook 'view.layout.styles',
path: '/plugin/rpvhost/style/green.css'
unless config.plugins.rpvhost.index_page == false
app.express.get '/', (req, res) ->
exports.render 'index', req, {}, (html) ->

View File

@@ -63,13 +63,16 @@ exports.registerHook 'app.started',
shadowsocks.initSupervisor ->
exports.registerServiceHook 'enable',
filter: (req, callback) ->
shadowsocks.initAccount req.account, callback
filter: (account, callback) ->
shadowsocks.initAccount account, callback
exports.registerServiceHook 'disable',
filter: (req, callback) ->
shadowsocks.deleteAccount req.account, callback
filter: (account, callback) ->
shadowsocks.deleteAccount account, callback
app.express.use '/plugin/shadowsocks', require './router'
setInterval shadowsocks.monitoring, config.plugins.shadowsocks.monitor_cycle
if config.plugins.shadowsocks.monitor_cycle
exports.registerHook 'app.started',
action: ->
setInterval shadowsocks.monitoring, config.plugins.shadowsocks.monitor_cycle

View File

@@ -0,0 +1,2 @@
module.exports = (callback) ->
callback()

View File

@@ -22,17 +22,17 @@ exports.registerHook 'view.panel.widgets',
, callback
exports.registerServiceHook 'enable',
filter: (req, callback) ->
req.account.update
filter: (account, callback) ->
account.update
$set:
'pluggable.supervisor.programs': []
, callback
exports.registerServiceHook 'disable',
filter: (req, callback) ->
supervisor.removePrograms req.account, ->
supervisor.updateProgram req.account, null, ->
req.account.update
filter: (account, callback) ->
supervisor.removePrograms account, ->
supervisor.updateProgram account, null, ->
account.update
$unset:
'pluggable.supervisor': true
, callback

View File

@@ -0,0 +1,2 @@
module.exports = (callback) ->
callback()

View File

@@ -12,7 +12,7 @@
it 'GET /:category/:title', (done) ->
agent.get '/wiki/FAQ/Billing.md'
.expect 200
.expect if config.plugins.wiki.disable_default_wiki then 404 else 200
.end done
it 'GET /:category/:title when not exist', (done) ->