coreybutler / node-windows

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

Multiple services of the same script leads to an error when uninstalling one of these services #195

Closed loebi-ch closed 6 years ago

loebi-ch commented 6 years ago

I have a node.js socket IO server: socket-io-server.js

I installed multiple services of this script with node-windows with different names (i.e. "Socket IO Server Port 5001", "Socket IO Server Port 5002") using the same script (socket-io-server.js). That works.

If I uninstall the service "Socket IO Server Port 5002", it works actually, it's uninstalled (and the other service is still installed), but an error is thrown. Node-windows tries to delete also the log file of the other service which should not be touched...

fs.js:1080
  return binding.unlink(pathModule._makeLong(path));
                 ^

Error: EBUSY: resource busy or locked, unlink 'C:\Projects\MyProject\SocketIO\daemon\socketioserverport5001.err.log'
    at Object.fs.unlinkSync (fs.js:1080:18)
    at rm (C:\Users\admin\AppData\Roaming\npm\node_modules\node-windows\lib\daemon.js:586:22)
    at C:\Users\admin\AppData\Roaming\npm\node_modules\node-windows\lib\daemon.js:605:17
    at Array.forEach (native)
    at C:\Users\admin\AppData\Roaming\npm\node_modules\node-windows\lib\daemon.js:604:22
    at ChildProcess.exithandler (child_process.js:201:7)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:194:7)
    at maybeClose (internal/child_process.js:899:16)
    at Socket.<anonymous> (internal/child_process.js:342:11)
jdziat commented 6 years ago

You need to change the location of the daemon or use a different directory for the log file. That's where the conflict is coming from. This isn't a node-windows problem. Closing this issue.

xeroxstar commented 5 years ago

How do we change the directory for the log with node-windows module? The way i found to fix it is by creating a new directory with fs :

const fs       = require('fs');
const svc  = new service({
        name         : "package name",
        description  : "what ever description",
        script       : "script.js"
});
svc._directory = __dirname + "/yourdirectory/"
if (!fs.existsSync(svc._directory)){
         fs.mkdirSync(svc._directory);
}

but i was wondering if there an option to create a new dir with node-windows? Thanks

jdziat commented 5 years ago

This is just a wrapper for winsw so any options from one should be available from the other. Maybe some more context around your use case and a new issue?