Permalink
Browse files

Rename option attach to detached

  • Loading branch information...
1 parent 8874c21 commit 7762b3de47fadd5026e52cda46179cc8e2f3417e @wdavidw committed Jul 31, 2012
View
28 changes.md
@@ -2,6 +2,34 @@
List of API changes and enhancements
====================================
+Version 0.2.9
+-------------
+
+Rename `attach` option to `detached` in start_stop
+
+Version 0.2.8
+-------------
+
+Broader Node.js requirement to 0.6
+
+Version 0.2.7
+-------------
+
+Fix Win7 completion (by [t101jv](https://github.com/t101jv))
+Fix compatibility with Node.js version 0.8
+
+Version 0.2.6
+-------------
+
+Reflect latest CoffeeScript strict mode
+
+Version 0.2.5
+-------------
+
+Add cmd and path options to http plugin
+Stylus plugin
+StartStop script improvement
+
Version 0.2.4
-------------
View
2 lib/plugins/cloud9.coffee
@@ -19,7 +19,7 @@ Options:
- `ip` , IP address where Cloud9 will serve from. Defaults to `"127.0.0.1"`.
- `port` , Port number where Cloud9 will serve from. Defaults to `3000`.
- `workspace`, Path to the workspace that will be loaded in Cloud9, Defaults to `Shell.set('workspace')`.
-- `attach` , Wether the Cloud9 process should be attached to the current process. If not defined, default to `false` (the server run as a daemon).
+- `detached` , Wether the Cloud9 process should be attached to the current process. If not defined, default to `false` (the server doesn't run as a daemon).
- `pidfile` , Path to the file storing the daemon process id. Defaults to `"/.node_shell/#{md5}.pid"`
- `stdout` , Writable stream or file path to redirect cloud9 stdout.
- `stderr` , Writable stream or file path to redirect cloud9 stderr.
View
2 lib/plugins/coffee.coffee
@@ -26,7 +26,7 @@ Options:
- `output` , Directory where compiled JavaScript files are written. Used in conjunction with "compile".
- `lint` , If the `jsl` (JavaScript Lint) command is installed, use it to check the compilation of a CoffeeScript file.
- `require` , Load a library before compiling or executing your script. Can be used to hook in to the compiler (to add Growl notifications, for example).
-- `attach` , Wether the Coffee process should be attached to the current process. If not defined, default to `false` (the server run as a daemon).
+- `detached` , Wether the Coffee process should be attached to the current process. If not defined, default to `false` (the server doesn't run as a daemon).
- `pidfile` , Path to the file storing the daemon process id. Defaults to `"/.node_shell/#{md5}.pid"`
- `stdout` , Writable stream or file path to redirect cloud9 stdout.
- `stderr` , Writable stream or file path to redirect cloud9 stderr.
View
2 lib/plugins/http.coffee
@@ -22,7 +22,7 @@ The following properties may be provided as settings:
Properties derived from the start_stop utility:
-- `attach` Wether the HTTP process should be attached to the current process. If not defined, default to `false` (the server run as a daemon).
+- `detached` Wether the HTTP process should be attached to the current process. If not defined, default to `false` (the server doesn't run as a daemon).
- `pidfile` Path to the file storing the daemon process id. Defaults to `"/.node_shell/#{md5}.pid"`
- `stdout` Writable stream or file path to redirect the server stdout.
- `stderr` Writable stream or file path to redirect the server stderr.
View
2 lib/plugins/redis.coffee
@@ -8,7 +8,7 @@ Redis Plugin
Register two commands, `redis start` and `redis stop`. The following properties may be provided as settings:
- `config` , Path to the configuration file. Required to launch redis.
-- `attach` , Wether the Redis process should be attached to the current process. If not defined, default to `false` (the server run as a daemon).
+- `detached` , Wether the Redis process should be attached to the current process. If not defined, default to `false` (the server doesn't run as a daemon).
- `pidfile` , Path to the file storing the daemon process id. Defaults to `"/.node_shell/#{md5}.pid"`
- `stdout` , Writable stream or file path to redirect cloud9 stdout.
- `stderr` , Writable stream or file path to redirect cloud9 stderr.
View
35 lib/start_stop.coffee
@@ -1,6 +1,6 @@
crypto = require 'crypto'
-{exec} = require 'child_process'
+{exec, spawn} = require 'child_process'
fs = require 'fs'
path = require 'path'
exists = fs.exists or path.exists
@@ -27,7 +27,7 @@ module.exports = start_stop =
`options` , Object with the following properties:
* `cmd` , Command to run
- * `attach` , Attach the child process to the current process
+ * `detached` , Detached the child process from the current process
* `pidfile` , Path to the file storing the child pid
* `stdout` , Path to the file where standard output is redirected
* `stderr` , Path to the file where standard error is redirected
@@ -40,7 +40,10 @@ module.exports = start_stop =
###
start: (options, callback) ->
- unless options.attach
+ if options.attach?
+ console.log 'Option attach was renamed to attached to be consistent with the new spawn option'
+ options.detached = not options.attach
+ if options.detached
cmdStdout =
if typeof options.stdout is 'string'
then options.stdout else '/dev/null'
@@ -99,7 +102,7 @@ module.exports = start_stop =
not provided, can be guessed from the `cmd` option used to start the process.
`options` , Object with the following properties:
- * `attach` , Attach the child process to the current process
+ * `detached` , Detach the child process to the current process
* `cmd` , Command used to run the process, in case no pidfile is provided
* `pid` , Pid to kill in attach mode
* `pidfile` , Path to the file storing the child pid
@@ -112,8 +115,12 @@ module.exports = start_stop =
###
stop: (options, callback) ->
+ if options.attach?
+ console.log 'Option attach was renamed to attached to be consistent with the new spawn option'
+ options.detached = not options.attach
+ # Stoping a provided PID
if typeof options is 'string' or typeof options is 'number'
- options = {pid: parseInt(options, 10), attach: true}
+ options = {pid: parseInt(options, 10), detached: false}
kill = (pid, callback) ->
# Not trully recursive, potential scripts:
# http://machine-cycle.blogspot.com/2009/05/recursive-kill-kill-process-tree.html
@@ -127,7 +134,7 @@ module.exports = start_stop =
"""
exec cmds, (err, stdout, stderr) ->
callback err
- unless options.attach
+ if options.detached
start_stop.pid options, (err, pid) ->
return callback err if err
return callback null, false unless pid
@@ -155,9 +162,9 @@ module.exports = start_stop =
otherwise it is set to false.
`options` , Object with the following properties:
- * `attach` , True if the child process is attached to the current process
+ * `detached` , True if the child process is not attached to the current process
* `cmd` , Command used to run the process, in case no pidfile is provided
- * `pid` , Pid to kill in attach mode
+ * `pid` , Pid to kill if not running in detached mode
* `pidfile` , Path to the file storing the child pid
@@ -168,8 +175,11 @@ module.exports = start_stop =
###
pid: (options, callback) ->
+ if options.attach?
+ console.log 'Option attach was renamed to attached to be consistent with the new spawn option'
+ options.detached = not options.attach
# Attach mode
- if options.attach
+ unless options.detached
return new Error 'Expect a pid property in attached mode' unless options.pid?
return callback null, options.pid
# Deamon mode
@@ -190,7 +200,7 @@ module.exports = start_stop =
argument with a pidfile property unless already present.
`options` , Object with the following properties:
- * `attach` , True if the child process is attached to the current process
+ * `detached` , True if the child process is not attached to the current process
* `cmd` , Command used to run the process, in case no pidfile is provided
* `pid` , Pid to kill in attach mode
* `pidfile` , Path to the file storing the child pid
@@ -202,7 +212,10 @@ module.exports = start_stop =
###
file: (options, callback) ->
- return callback null, null, false if options.attach
+ if options.attach?
+ console.log 'Option attach was renamed to detached to be consistent with the spawn API'
+ options.detached = not options.attach
+ return callback null, null, false unless options.detached
start = ->
return pidFileExists() if options.pidfile
dir = path.resolve process.env['HOME'], '.node_shell'
View
2 samples/cloud9/sample.js
@@ -14,7 +14,7 @@
stdout: __dirname+'/cloud9.out.log',
stderr: __dirname+'/cloud9.err.log',
pidfile: __dirname+'/cloud9.pid',
- attach: false
+ detached: true
}));
app.use(shell.router({
shell: app
View
2 samples/coffee/sample.coffee
@@ -15,7 +15,7 @@
stdout: __dirname + '/coffee.out.log'
stderr: __dirname + '/coffee.err.log'
pidfile: __dirname + '/coffee.pid'
- attach: false
+ detached: true
app.use shell.help
shell: app
introduction: true
View
2 samples/http/sample.js
@@ -18,7 +18,7 @@
stdout: __dirname + '/logs/http.out.log',
stderr: __dirname + '/logs/http.err.log',
pidfile: __dirname + '/tmp/http.pid',
- attach: false
+ detached: true
}));
app.use(shell.router({shell: app}));
app.use(shell.help({shell: app, introduction: true}));
View
3 samples/redis/sample.js
@@ -17,7 +17,8 @@ app.configure(function() {
}));
app.use(shell.redis({
config: 'redis.conf',
- pidfile: 'redis.pid'
+ pidfile: 'redis.pid',
+ detached: true
}));
app.use(shell.router({
shell: app
View
4 test/plugin_http.coffee
@@ -4,14 +4,14 @@ http = require 'http'
shell = require '..'
describe 'Plugin HTTP', ->
- it 'should start and stop an HTTP server', (next) ->
+ it 'should start and stop an HTTP server in attach mode', (next) ->
app = shell
workspace: "#{__dirname}/plugin_http"
command: null
stdin: new shell.NullStream
stdout: new shell.NullStream
app.configure ->
- app.use shell.http attach: true
+ app.use shell.http detached: false
app.use shell.router shell: app
app.run 'http start'
setTimeout ->
View
30 test/start_stop.coffee
@@ -6,32 +6,32 @@ should = require 'should'
start_stop = require '../lib/start_stop'
describe 'StartStop', ->
- it 'Test daemon # start and stop', (next) ->
+ it 'should detach a child, start and stop', (next) ->
cmd = "node #{__dirname}/start_stop/server.js"
# Start the process
- start_stop.start cmd: cmd, (err, pid) ->
+ start_stop.start cmd: cmd, detached: true, (err, pid) ->
should.not.exist err
pid.should.be.a 'number'
# Check if process started
start_stop.running pid, (err, running) ->
should.not.exist err
running.should.be.true
# Stop process
- start_stop.stop cmd: cmd, (err) ->
+ start_stop.stop cmd: cmd, detached: true, (err) ->
should.not.exist err
# Check if process stoped
start_stop.running pid, (err, running) ->
should.not.exist err
running.should.be.false
next()
- it 'Test daemon # stop inactive process', (next) ->
+ it 'should detach a child and stop inactive process', (next) ->
cmd = "node #{__dirname}/start_stop/server.js"
# Stop process
- start_stop.stop cmd:cmd, (err, stoped) ->
+ start_stop.stop cmd:cmd, detached: true, (err, stoped) ->
should.not.exist err
stoped.should.be.false
next()
- it 'Test daemon # stop inactive process with pidfile # relax', (next) ->
+ it 'should detach a child and stop inactive process with pidfile', (next) ->
cmd = "node #{__dirname}/start_stop/server.js"
pidfile = "#{__dirname}/start_stop/pidfile"
fs.writeFile pidfile, "1234567", (err) ->
@@ -40,14 +40,18 @@ describe 'StartStop', ->
should.not.exist err
running.should.be.false
# Stop process
- start_stop.stop {cmd:cmd, pidfile: pidfile}, (err, stoped) ->
+ start_stop.stop cmd:cmd, pidfile: pidfile, detached: true, (err, stoped) ->
should.not.exist err
stoped.should.be.false
# Pidfile shall be removed even if pid is invalid
exists pidfile, (running) ->
running.should.be.false
next()
- it 'Test daemon # stop inactive process with pidfile # strict', (next) ->
+ it 'should detach a child and honor the strict option', (next) ->
+ # From the API
+ # Send an error when a pid file exists and reference an unrunning pid.
+ # Exist both in the start and stop functions
+ # todo: test in start function
cmd = "node #{__dirname}/start_stop/server.js"
pidfile = "#{__dirname}/start_stop/pidfile"
fs.writeFile pidfile, "1234567", (err) ->
@@ -56,23 +60,23 @@ describe 'StartStop', ->
should.not.exist err
running.should.be.false
# Stop process
- start_stop.stop {cmd:cmd, pidfile: pidfile, strict: true}, (err, stoped) ->
+ start_stop.stop cmd:cmd, pidfile: pidfile, strict: true, detached: true, (err, stoped) ->
err.should.be.an.instanceof Error
# Pidfile shall be removed even if pid is invalid
exists pidfile, (running) ->
running.should.be.false
next()
- it 'should throw an error if pidfile is not in a existing directory', (next) ->
+ it 'should detach a child and throw an error if pidfile not in directory', (next) ->
cmd = "node #{__dirname}/start_stop/server.js"
pidfile = "#{__dirname}/doesnotexist/pidfile"
- start_stop.start cmd:cmd, pidfile: pidfile, (err, stoped) ->
+ start_stop.start cmd:cmd, pidfile: pidfile, detached: true, (err, stoped) ->
err.should.be.an.instanceof Error
err.message.should.eql 'Pid directory does not exist'
next()
- it 'Test attach', (next) ->
+ it 'should attach a child', (next) ->
cmd = "node #{__dirname}/start_stop/server.js"
# Start the process
- start_stop.start {cmd: cmd, attach: true}, (err, pid) ->
+ start_stop.start cmd: cmd, detached: false, (err, pid) ->
should.not.exist err
pid.should.be.a 'number'
# Check if process started
View
2 test/start_stop/test_attach.coffee
@@ -4,6 +4,6 @@ start_stop = require '../../lib/start_stop'
start_stop.start
cmd: "#{__dirname}/server.js"
- attach: true
+ detached: false
, (err, pid) ->
# Keep the process active

0 comments on commit 7762b3d

Please sign in to comment.