Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Killing Spawned Processes when Grunt Exits

Tags:

gruntjs

I am currently trying to perform several steps that require tasks to be spawned into child processes. For example:

  1. Watch files
  2. Start up my Static Site Generator's Preview Server

I can easily use a tasks like grunt-concurrent to have both of these run simultaneously. However, when I exit grunt, the child process (in this case - the static site generator which I am running using grunt-shell) keeps running. I would like to have these tasks run simultaneously - but also have them be killed when grunt exits.

Thoughts?

like image 430
dtuckernet Avatar asked Apr 24 '13 17:04

dtuckernet


1 Answers

Not sure how this works with grunt-shell. But if you'd setup a custom grunt task to run your server you could try somthing like:

  var spawn = require('child_process').spawn;
  var server = spawn('myserver', ['--foo']);
  process.on('exit', function() {
     grunt.log.writeln('killing myserver...');
     server.kill();
     grunt.log.writeln('killed myserver');
  });
like image 91
schibum Avatar answered Nov 08 '22 00:11

schibum