@@ -251,16 +251,8 @@ module.exports.emit = function (topic, data) {
251251module . exports . monitor = function ( ) {
252252
253253 if ( typeof ( this . api ) == 'undefined' ) {
254- agent . start ( ) ;
254+ this . start ( ) ;
255255 this . api = hcAPI . getAPI ( agent , module . exports ) ;
256- var headlessOutputDir = agent . getOption ( 'com.ibm.diagnostics.healthcenter.headless.output.directory' ) ;
257- if ( headlessOutputDir ) {
258- headlessZip . setHeadlessOutputDir ( headlessOutputDir ) ;
259- }
260- var headlessFilesToKeep = agent . getOption ( 'com.ibm.diagnostics.healthcenter.headless.files.to.keep' ) ;
261- if ( headlessFilesToKeep && ! isNaN ( headlessFilesToKeep ) && headlessFilesToKeep > 0 ) {
262- headlessZip . setFilesToKeep ( headlessFilesToKeep ) ;
263- }
264256 }
265257 return this . api ;
266258} ;
@@ -296,11 +288,20 @@ module.exports.getJSONProfilingMode = function() {
296288 return jsonProfilingMode ;
297289}
298290
299- module . exports . start = function ( ) {
291+ module . exports . start = function start ( ) {
300292 agent . setOption ( propertyMappings [ 'applicationID' ] , main_filename ) ;
301293 var headlessOutputDir = agent . getOption ( 'com.ibm.diagnostics.healthcenter.headless.output.directory' ) ;
302294 if ( headlessOutputDir ) {
303295 headlessZip . setHeadlessOutputDir ( headlessOutputDir ) ;
304296 }
297+ var headlessFilesToKeep = agent . getOption ( 'com.ibm.diagnostics.healthcenter.headless.files.to.keep' ) ;
298+ if ( headlessFilesToKeep && ! isNaN ( headlessFilesToKeep ) && headlessFilesToKeep > 0 ) {
299+ headlessZip . setFilesToKeep ( headlessFilesToKeep ) ;
300+ }
301+ var am = this ;
305302 agent . start ( ) ;
303+ process . on ( 'exit' , function ( ) {
304+ am . stop ( ) ;
305+ } ) ;
306306}
307+
0 commit comments