-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0c0d039
Showing
9 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
.DS_Store | ||
test/meta |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ." | ||
} | ||
} |