Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect when running bash shell in Windows #47

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/commands/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = function (config) {
result.environment = command.detail.environment
console.log('run: ' + result.run)
console.log('directory: ' + command.detail.cwd)
console.log('repository: ' + (container.repository_url || 'not set'))
console.log('repository: ' + (container.repository_url || 'not set ' + command))
console.log('test: ' + (container.test || 'not set'))

if (display === 'full') {
Expand Down
34 changes: 32 additions & 2 deletions lib/commands/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,26 @@ module.exports = function () {

function run (system, container, command, commandName, cb) {
var cmd = command
if (isWin) {
cmd = 'cmd /C "' + command + '"'
if (winBash()) {
cmd = 'bash -c "' + command + '"'
} else if (isWin) {
cmd = 'cmd /C ' + command
} else {
cmd = 'bash -c "' + command + '"'
}
processRunner.runCommand(system, container, cmd, commandName, cb)
}


function winBash () {
var bashos = 'windows'
var path = process.env.PATH
if ((path.indexOf('\\usr\\bin') > -1)) {
return bashos
}
}


function shell (system, command, cb) {
var container
var c
Expand Down Expand Up @@ -69,9 +80,28 @@ module.exports = function () {
}



function papply (system, command, cb) {
async.each(_.keys(system.topology.containers), function (key, next) {
if (system.topology.containers[key].type === 'process' || system.topology.containers[key].type === 'node') {
console.log('[' + system.topology.containers[key].name + ']')
run(system, system.topology.containers[key], command, 'apply', function (err) {
next(err)
})
} else {
next()
}
}, function (err) {
cb(err || null)
})
}



return {
run: run,
shell: shell,
papply: papply,
apply: apply
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = function () {
processRunner.runCommand(system, container, 'git branch', 'status', cb)
})
} else {
cb('status not suuported for this container type: ' + container.type)
cb('status not supported for this container type: ' + container.type)
}
}

Expand Down
23 changes: 12 additions & 11 deletions lib/support/processRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ module.exports = function () {
var args
var env
var toks

toks = util.tokenizeCommand(container.run)
if (container.type === 'node') {
cmd = process.argv[0]

if (toks[0] === 'node') {
args = toks.splice(1)
} else {
Expand All @@ -53,15 +51,16 @@ module.exports = function () {
}

env = Object.assign({}, process.env)

if (container.environment) {
env = Object.assign(env, container.environment)
}


if (mode !== 'preview') {
var options = {cwd: cwd, env: env, stdio: ['ignore', 'pipe', 'pipe'], detached: false}
if (container.type === 'node' && !isWin) {
options.stdio[3] = 'ipc'
}
if (container.type === 'node' && !isWin) { options.stdio[3] = 'ipc' }
if (isWin && cmd === 'npm') { cmd = 'npm.cmd' }

child = spawn(cmd, args, options)
child.unref()
Expand Down Expand Up @@ -91,7 +90,6 @@ module.exports = function () {
}



var start = function (system, mode, container, exitCb, cb) {
if (container && container.run) {
run(mode, container, exitCb, cb)
Expand All @@ -102,8 +100,8 @@ module.exports = function () {
}



var kill = function kill (container, pid, signal, cb) {
var kill = function kill (container, pid, cb) {
var signal = container.terminate
if (pid) {
psTree(pid, function (err, children) {
async.eachSeries(children, function (child, next) {
Expand All @@ -113,7 +111,7 @@ module.exports = function () {
} catch (e) {}
next()
}, function () {
console.log('sending ' + signal + ' to parent process: ' + pid)
console.log('sending ' + signal + ' to parent process: ' + container.name + ' ' + pid)
try {
process.kill(pid, signal)
} catch (e) {}
Expand All @@ -126,7 +124,9 @@ module.exports = function () {


var stop = function stop (container, pid, cb) {
kill(container, pid, 'SIGKILL', cb)
// kill(container, pid, 'SIGKILL', cb)
kill(container, pid, cb)

}


Expand Down Expand Up @@ -171,7 +171,8 @@ module.exports = function () {
return {
start: start,
stop: stop,
runCommand: runCommand
runCommand: runCommand,
run: run
}
}

2 changes: 2 additions & 0 deletions lib/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ module.exports = function () {
if (!util.isExecutableContainer(container)) { return cb('container not executable: ' + name) }
if (debugMode && container.type !== 'node') { return cb('debug only available for conainer type node: ' + name) }
if ((container.type === 'container' || container.type === 'docker') && !system.global.run_containers) { return cb('run containers disabled - skipping: ' + name) }
if (container.status === 'disabled') { return cb('[' + container.name + '] is ' + container.status) }

console.log('starting: ' + container.name + ' [' + (container.run ? container.run : container.image) + ']')
container.debugMode = debugMode
Expand Down Expand Up @@ -284,6 +285,7 @@ module.exports = function () {
if (container.monitor || container.process.monitor) {
unwatch(system, container.name, function () { next() })
} else {
console.log('Failed to unwatch: [' + container.name + ']. Process may not yet be monitored.')
next(null)
}
}, function () { cb(null) })
Expand Down
Loading