I have created a gulpfile.js
to start my servers, and its content can be seen below.
gulp.task('default', function () {
if(!fs.statSync('/etc/aptly.conf').isFile()){
process.exit();
return;
}
console.info('Starting static file server SimpleHTTPServer on 0.0.0.0:8080');
aptly_static = spawn('python', ['-m', 'SimpleHTTPServer', '8080'], {'cwd': '/opt/aptly/public', 'stdio': 'inherit'});
console.info('Starting Django runserver on 0.0.0.0:8000');
django = spawn('python', ['manage.py', 'runserver', '0.0.0.0:8000'], {'stdio': 'inherit'});
console.info('Starting Aptly api serve on 0.0.0.0:4416');
aptly_api = run('aptly api serve -listen="0.0.0.0:4416"').exec().pipe(gulp.dest('/tmp/aptlylog'));
return watchLess('src/**/*.less')
.pipe(debug())
.pipe(reLess)
.pipe(gulp.dest('dist/dist'));
The problem is if less preprocessor crashes for any reason, the gulpfile.js daemon exits poorly. The child processes python manage.py runserver
python -m SimpleHTTPServer
aptly api serve
will still be running.
I have had to painstakingly terminate these by using a ps -aux | grep runserver
and similar to find the PID to delete via sudo kill -9 $PID
.
Is there a way to directly kill all the processes if my gulpfile.js crashes unexpectedly?