Skip to content

Commit

Permalink
messing around
Browse files Browse the repository at this point in the history
  • Loading branch information
max-mapper committed Mar 20, 2015
0 parents commit 0c0d039
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.DS_Store
test/meta
Binary file added images/Status.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/StatusHighlighted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 96 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
var path = require('path')

var app = require('app')
var Menu = require('menu')
var Tray = require('tray')

var ms = require('ms')
var Mongroup = require('mongroup')
var fs = require('fs')
var mkdir = require('mkdirp').sync

var icon, menu

app.on('ready', function() {
// main.js
var template = []

var iconPath = path.join(__dirname, 'images', 'Status.png')
var configFile = './test/config.json'
var conf = require(configFile)
var dir = path.dirname(configFile)
process.chdir(dir)
mkdir(conf.logs || 'logs')
mkdir(conf.pids || 'pids')

conf.mon = path.join(__dirname, 'mon')

var group = new Mongroup(conf)


icon = new Tray(iconPath)
group.procs.forEach(function(proc) {
var state = proc.state()

var uptime
if (state === 'alive') uptime = ms(Date.now() - proc.mtime(), { long: true })

var item = {
label: proc.name,
submenu: [
{label: "State: " + state},
{label: "PID: " + proc.pid}
]
}

if (uptime) item.submenu.push({label: "Uptime: " + uptime})

template.push(item)
})

template.push({
type: 'separator'
}, {
label: 'Actions',
submenu: [{
label: 'Restart All',
click: function() {
restartAll(function (err) {
if (err) throw err
})
}
}, {
label: 'Stop All',
click: function() {
stopAll(function (err) {
if (err) throw err
})
}
}]
})

menu = Menu.buildFromTemplate(template)
icon.setContextMenu(menu)

function restartAll(cb) {
stopAll(function (err1) {
startAll(function (err2) {
if (cb) cb(err1 || err2)
})
})
}

function startAll(cb) {
group.start(Object.keys(conf.processes), function (err) {
if (err) return cb(err)
cb()
})
}

function stopAll(cb) {
group.stop(Object.keys(conf.processes), 'SIGQUIT', function (err) {
if (cb) return cb(err)
cb()
})
}
})
Binary file added mon
Binary file not shown.
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "monu",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD",
"dependencies": {
"auto-launch": "^0.1.15",
"mkdirp": "^0.5.0",
"mongroup": "maxogden/node-mongroup#monbin",
"ms": "^0.7.0",
"npm-execspawn": "^1.0.6"
}
}
7 changes: 7 additions & 0 deletions test/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"logs": "./meta/logs",
"pids": "./meta/pids",
"processes": {
"web-1": "http-server ."
}
}

0 comments on commit 0c0d039

Please sign in to comment.