plugin.writeConfig

This commit is contained in:
jysperm
2014-07-19 03:14:12 +08:00
parent 765f43005b
commit ec8d739c86
7 changed files with 30 additions and 37 deletions

View File

@@ -3,12 +3,6 @@ all: install
install:
npm install
build: install
node node_modules/coffee-script/bin/coffee -c .
clean:
find . -path './node_modules' -prune -o -name '*.js' -exec rm -fr {} \;
clean_socket:
-rm ../rootpanel.sock

View File

@@ -20,11 +20,9 @@ RP3 的核心功能包括:
make install # 安装依赖
make run # 直接运行
make test # 运行测试
make build # 生成 .js
make clean # 删除生成的 .js
make start # 以 pm2 启动
make restart # 重启 pm2 进程
make stop # 停止 pm2 进程
make start # 以 forever 启动
make restart # 重启 forever 进程
make stop # 停止 forever 进程
## 技术构成

View File

@@ -1,4 +1,7 @@
child_process = require 'child_process'
path = require 'path'
tmp = require 'tmp'
fs = require 'fs'
i18n = require './i18n'
config = require './../config'
@@ -15,3 +18,16 @@ exports.loadPlugins = (app) ->
if plugin.action
app.use ('/plugin/' + name), plugin.action
exports.writeConfig = (path, content, callback) ->
tmp.file
mode: 0o750
, (err, filepath, fd) ->
fs.writeSync fd, content, 0, 'utf8'
fs.closeSync fd
child_process.exec "sudo cp #{filepath} #{path}", (err) ->
throw err if err
fs.unlink path, ->
callback

View File

@@ -1,7 +1,6 @@
child_process = require 'child_process'
service = require './service'
plugin = require '../../core/plugin'
configure = require './configure'
{requestAuthenticate, getParam} = require '../../core/router/middleware'

View File

@@ -1,9 +1,10 @@
child_process = require 'child_process'
jade = require 'jade'
path = require 'path'
tmp = require 'tmp'
fs = require 'fs'
plugin = require '../../core/plugin'
mAccount = require '../../core/model/account'
template =
@@ -36,18 +37,10 @@ module.exports =
user_configure = _.template template.user_configure,
sites: sites_configure
tmp.file
mode: 0o750
, (err, filepath, fd) ->
fs.writeSync fd, user_configure, 0, 'utf8'
fs.closeSync fd
child_process.exec "sudo cp #{filepath} /etc/nginx/sites-enabled/#{account.username}.conf", (err) ->
plugin.writeConfig "/etc/nginx/sites-enabled/#{account.username}.conf", user_configure, ->
child_process.exec 'sudo service nginx reload', (err) ->
throw err if err
child_process.exec 'sudo service nginx reload', (err) ->
throw err if err
callback()
callback()
widget: (account, callback) ->
jade.renderFile path.join(__dirname, 'view/widget.jade'),

View File

@@ -1,7 +1,6 @@
child_process = require 'child_process'
service = require './service'
plugin = require '../../core/plugin'
{assertInService} = require '../../core/router/middleware'
mAccount = require '../../core/model/account'

View File

@@ -23,26 +23,20 @@ module.exports =
callback()
switch: (account, is_enable, callback) ->
callbackback = ->
restartPhpfpm = ->
child_process.exec 'sudo service php5-fpm restart', (err) ->
throw err if err
callback()
if is_enable
tmp.file
mode: 0o750
, (err, filepath, fd) ->
config_content = _.template (fs.readFileSync path.join(__dirname, 'template/fpm-pool.conf')).toString(),
account: account
fs.writeSync fd, config_content, 0, 'utf8'
fs.closeSync fd
config_content = _.template (fs.readFileSync path.join(__dirname, 'template/fpm-pool.conf')).toString(),
account: account
child_process.exec "sudo cp #{filepath} /etc/php5/fpm/pool.d/#{account.username}.conf", (err) ->
throw err if err
callbackback()
plugin.writeConfig "/etc/php5/fpm/pool.d/#{account.username}.conf", config_content, ->
restartPhpfpm()
else
child_process.exec "sudo rm /etc/php5/fpm/pool.d/#{account.username}.conf", ->
callbackback()
restartPhpfpm()
widget: (account, callback) ->
jade.renderFile path.join(__dirname, 'view/widget.jade'), {account: account}, (err, html) ->