coreybutler / node-windows

Windows support for Node.JS scripts (daemons, eventlog, UAC, etc).
Other
2.81k stars 356 forks source link

service uninstall dies when other apps share the daemon folder #117

Open cpjones999 opened 8 years ago

cpjones999 commented 8 years ago

I needed to uninstall a service I had previously installed and had several other services in the same folder so they and their associated log files were in the same daemon folder as well. I needed to reinstall the service to increase default memory size using:

var nodeArg= '--max-old-space-size=4096 --harmony';

var svc = new Service({ name: botname + ' Service', description:botname + ' Service', script: script, env: [{ name: 'NODE_ENV', value: process.env['NODE_ENV'] }], flags: nodeArg // <--- here });

I attempted to uninstall a specific service and found that the uninstall died due to locked log files from another service that was running which I figured out was due to this piece of code in daemon.js:

// Remove all other files var _files = fs.readdirSync(me.root); _files.forEach(function(f){ rm(f); });

So I switched it to use glob as:

var glob= require('glob'); var _files = glob.sync(path.join(me.root,me.id + '*.out.log')); _files.forEach(function(f){ rm(f); });

This fixed the problem.

coreybutler commented 8 years ago

Feel free to submit this as a PR. If you decided to, these changes would also be relevant to node-mac and node-linux.