Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit af5b34555ac6c4c9191f05f29ecec81e1f37d7ac @FGRibreau committed Nov 17, 2011
@@ -0,0 +1,2 @@
+oldStuff
+node_modules
@@ -0,0 +1,13 @@
+Forever Web UI __WORK IN PROGRESS__
+===================================
+
+Just a little experimentation with Backbone.js
+
+ git clone git@github.com:FGRibreau/forever-webui.git
+ cd forever-webui/
+
+ npm install
+
+ node app.js
+
+![Screen shot 1](/fgribreau/forever-webui/raw/master/public/img/screenshot.png)
@@ -0,0 +1,158 @@
+express = require 'express'
+async = require 'async'
+fs = require 'fs'
+forever = require 'forever'
+
+#todo
+class foreverUI
+
+ constructor: ->
+ # ~/.forever/pids/
+ #todo
+ @foreverHome = process.env.HOME+'/.forever'
+
+ @configJson = @_readConfSync("#{@foreverHome}/config.json")
+
+ @pidsPath = @configJson.pidPath
+
+
+ _readConfSync: (filename) ->
+ data = fs.readFileSync(fs.realpathSync(filename), 'utf8')
+ conf = {}
+
+ return conf if(!data)
+
+ try
+ conf = JSON.parse(data)
+
+ catch ignoreError
+ return {}
+
+ return conf
+
+ # Get process logs
+ getInfo: (pid, cb) ->
+
+ pid = parseInt(pid, 10)
+
+ proc = @process.filter((o) ->
+ o.pid == pid
+ )
+
+ return cb {} if proc.length != 1
+
+ proc = proc[0]
+
+ out = ''
+
+ async.map([proc.logFile, proc.outFile, proc.errFile].filter((s) -> s != undefined), (filename, cb) ->
+
+ fs.readFile(filename, (err, data) ->
+ d = data.toString().trim()
+
+ if(!d || d == '\n')
+ cb(null, [filename, 'Empty log'])
+ else
+ cb(null, [filename, data.toString()])
+ )
+
+ , (err, results) ->
+ cb results
+ )
+
+
+ getProcess: (cb) ->
+
+ @process = []
+
+ fs.readdir @pidsPath, (err, files) =>
+
+ # todo
+ files.forEach((filename) =>
+ return false if filename.lastIndexOf('.fvr') == -1
+
+ _conf = @_readConfSync "#{@pidsPath}/#{filename}"
+ _conf.id = _conf.pid
+
+ @process.push _conf
+ )
+
+ cb @process
+
+ stop: (cb) ->
+ cb {}
+
+ restart: (cb) ->
+ cb {}
+
+
+
+
+
+UI = new foreverUI()
+
+app = express.createServer()
+
+app.configure ->
+ app.use express.bodyParser()
+ app.use express.cookieParser()
+ app.register('.ejs', require('ejs'))
+ app.set('views', __dirname + '/views')
+ app.set('view engine', 'html')
+ app.use express.methodOverride()
+ app.use app.router
+
+app.configure "development", ->
+ app.use express.errorHandler(
+ dumpExceptions: true
+ showStack: true
+ )
+ app.use express.static(__dirname + "/public")
+
+app.configure "production", ->
+ app.use express.errorHandler()
+ app.use(express.static(__dirname + '/public', { maxAge: oneYear }))
+
+
+app.set 'view options',
+ layout: false
+
+
+app.get('/', (req, res) ->
+ res.render('index.ejs', { process: UI.process})
+)
+
+app.get('/refresh/', (req, res) ->
+ UI.getProcess (process) ->
+ res.send JSON.stringify(process), { 'Content-Type': 'text/javascript' }, 200
+)
+
+app.get('/processes', (req, res) ->
+ # Refresh process list (#todo use fs.watch instead)
+ UI.getProcess(() ->
+ res.send JSON.stringify(UI.process), { 'Content-Type': 'text/javascript' }, 200
+ )
+)
+
+app.get('/restart/:pid', (req, res) ->
+ UI.restart req.params.pid, (res) ->
+ res.send JSON.stringify(res), { 'Content-Type': 'text/javascript' }, 200
+)
+
+app.get('/stop/:pid', (req, res) ->
+ UI.stop req.params.pid, (res) ->
+ res.send JSON.stringify(res), { 'Content-Type': 'text/javascript' }, 200
+)
+
+app.get('/info/:pid', (req, res) ->
+ UI.getInfo req.params.pid, (infos) ->
+ res.send JSON.stringify(infos), { 'Content-Type': 'text/javascript' }, 200
+)
+
+
+UI.getProcess(() ->
+ console.log 'Listening on 127.0.0.1:3000'
+
+ #todo
+ app.listen 3000
+)
149 app.js

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,17 @@
+{
+ "name" : "forever-webui",
+ "description" : "Forever Web ui",
+ "keywords": ["forever","web ui"],
+ "version": "0.1.0",
+ "homepage": "http://fgribreau.com",
+ "dependencies": {
+ "async":"0.1.15",
+ "coffee-script":"*",
+ "express":">= 2.5.0",
+ "forever":">= 0.7.2"
+ },
+ "repository": "",
+ "author" : "Francois-Guillaume Ribreau <npm@fgribreau.com> (http://fgribreau.com)",
+ "main" : "index",
+ "engines": { "node": ">= 0.4.12" }
+}
@@ -0,0 +1,37 @@
+App.AppView = Backbone.View.extend({
+ el: $(".container"),
+
+ events:{
+ 'click .refresh': 'refresh'
+ },
+
+ initialize: function(processData) {
+ // Create our process collection
+ this.Processes = new App.ProcessList();
+
+ this.Processes.bind('all', this.updateAll, this);
+
+ // Will trigger the "all" event
+ this.Processes.reset(processData);
+ },
+
+ addOne: function(process){
+ var view = new App.ProcessView({model: process});
+ this.$("#process-list").append(view.render().el);
+ },
+
+ updateAll: function() {
+ this.$("#process-list").empty();
+ this.Processes.each(this.addOne, this);
+
+ this.render();
+ },
+
+ refresh: function(){
+ this.Processes.fetch();
+ },
+
+ render: function() {
+ this.$('#process-count').text(this.Processes.length);
+ }
+});
Oops, something went wrong.

0 comments on commit af5b345

Please sign in to comment.