Skip to content

Commit

Permalink
Add dropdown to select a custom kill signal
Browse files Browse the repository at this point in the history
  • Loading branch information
marcbachmann committed Nov 15, 2015
1 parent c0447c4 commit eaac6f1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
45 changes: 35 additions & 10 deletions configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,7 @@ var events = {
var procNameAttr = e.node.attributes['data-name']
var data = {task: action}
if (procNameAttr) data.name = procNameAttr.value
client.request('task', data, function (err, data) {
if (err) return throwError(err)
if (!data) return

if (Array.isArray(data)) {
renderAll(data)
} else if (data.name) {
state.detail.set(data)
}
})
execTask(data)
},

quit: function () {
Expand All @@ -46,6 +37,27 @@ var events = {
client.request('open-dir')
},

openKillMenu: function (e) {
var remote = require('remote')
var Menu = remote.require('menu')
var MenuItem = remote.require('menu-item')

function sendSignal (signal) {
return function () {
var procNameAttr = e.node.attributes['data-name']
execTask({task: 'stop', name: procNameAttr.value, signal: signal})
}
}

var menu = new Menu()
;['SIGTERM', 'SIGHUP', 'SIGINT', 'SIGKILL', 'SIGQUIT'].forEach(function (signal) {
menu.append(new MenuItem({ label: 'Send ' + signal, click: sendSignal(signal) }))
})

menu.popup(remote.getCurrentWindow())
return false
},

openLogsDir: function (e) {
client.request('open-logs-dir', {name: e.context.name})
}
Expand Down Expand Up @@ -84,6 +96,19 @@ client.on('show', function () {
if (currentProcess) getAndRender(currentProcess)
})

function execTask (task) {
client.request('task', task, function (err, data) {
if (err) return throwError(err)
if (!data) return

if (Array.isArray(data)) {
renderAll(data)
} else if (data.name) {
state.detail.set(data)
}
})
}

function render (ctx) {
var ract = new Ractive({
el: '#container',
Expand Down
3 changes: 3 additions & 0 deletions detail.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<div class="media-body">
Stop
</div>
<button class="btn btn-link" on-click="openKillMenu" data-name="{{name}}">
<span class="media-object icon icon-down-nav"></span>
</button>
</a>
</li>
<li class="table-view-cell media">
Expand Down
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ menu.on('ready', function ready () {

app.on('task', function task (req, next) {
if (req.body.task === 'startAll') start([], updateAll)
if (req.body.task === 'stopAll') stop([], updateAll)
if (req.body.task === 'stopAll') stop([], req.body.signal, updateAll)
if (req.body.task === 'restartAll') restart([], updateAll)
if (req.body.task === 'start') start([req.body.name], updateSingle)
if (req.body.task === 'stop') stop([req.body.name], updateSingle)
if (req.body.task === 'stop') stop([req.body.name], req.body.signal, updateSingle)
if (req.body.task === 'restart') restart([req.body.name], updateSingle)

function updateAll (err) {
Expand Down Expand Up @@ -158,7 +158,7 @@ function getProcessesStatus () {
}

function restart (procs, cb) {
stop(procs, function onstop (err1) {
stop(procs, 'SIGQUIT', function onstop (err1) {
start(procs, function onstart (err2) {
if (cb) cb(err1 || err2)
})
Expand All @@ -173,9 +173,10 @@ function start (procs, cb) {
})
}

function stop (procs, cb) {
function stop (procs, signal, cb) {
if (!signal) signal = 'SIGQUIT'
var group = new Mongroup(conf)
group.stop(procs, 'SIGQUIT', function onstop (err) {
group.stop(procs, signal, function onstop (err) {
if (!err || err.code === 'ENOENT') return cb()
cb(err)
})
Expand Down

0 comments on commit eaac6f1

Please sign in to comment.