Permalink
Browse files

Check presence of the parent directory storing the pid file

  • Loading branch information...
1 parent 1e3fdc8 commit cc14f651799d814accda569cbdbaeee4e1d4880a @wdavidw committed Jun 18, 2012
Showing with 12 additions and 2 deletions.
  1. +4 −2 lib/start_stop.coffee
  2. +8 −0 test/start_stop.coffee
@@ -58,8 +58,10 @@ module.exports = start_stop =
if code isnt 0
msg = "Process exit with code #{code}"
return callback new Error msg
- fs.writeFile options.pidfile, '' + pid, (err) ->
- callback null, pid
+ path.exists path.dirname(options.pidfile), (exists) ->
+ return callback new Error "Pid directory does not exist" unless exists
+ fs.writeFile options.pidfile, '' + pid, (err) ->
+ callback null, pid
# Do the job
start_stop.pid options, (err, pid) ->
return start callback unless pid
@@ -61,6 +61,13 @@ describe 'StartStop', ->
path.exists pidfile, (exists) ->
exists.should.be.false
next()
+ it 'should throw an error if pidfile is not in a existing directory', (next) ->
+ cmd = "node #{__dirname}/start_stop/server.js"
+ pidfile = "#{__dirname}/doesnotexist/pidfile"
+ start_stop.start cmd:cmd, pidfile: pidfile, (err, stoped) ->
+ err.should.be.an.instanceof Error
+ err.message.should.eql 'Pid directory does not exist'
+ next()
it 'Test attach', (next) ->
cmd = "#{__dirname}/start_stop/server.js"
# Start the process
@@ -79,3 +86,4 @@ describe 'StartStop', ->
should.not.exist err
exists.should.be.false
next()
+

0 comments on commit cc14f65

Please sign in to comment.