Giter VIP home page Giter VIP logo

node-windows's Issues

Event logging as non-admin?

Currently it looks like if I write to the event log, I get a UAC prompt with every message. Of course this doesn't happen if my program runs as an administrator, or, I presume, as a service.

Is there a way to write to the event log as a non-admin? It would be fine it UAC popped up the first time the log was created, but not with each entry.

Install Service not working on Windows 8.1 and .NET 4.5

I tried following script to run another node package as a service. Opened my nodejs commandprompt as administrator so I have the elevated rights. Nothing is happening. No Service running, no console output, no nothing. Let me know how I can get you more information.

var Service = require('node-windows').Service;

// Create a new service object
var svc = new Service({
    name: 'Subway IRC',
    description: 'IRC client in the browser, running on port 3000',
    script: 'E:\\subway\\subway'
});

// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install', function() {
    console.log('Service "%s" installed', svc.name);
    svc.start();
    console.log('Service "%s" started', svc.name);
});

svc.install();

Uninstall directory

The install function has a dir parameter but unfortunately, the uninstall has not. So when you try to uninstall a service installed with a custom dir param, it says: Uninstall was skipped because process does not exist or could not be found.

I can submit a patch if you want.

Elevate Process Exits Immediately

Normally, I might do something like this (using calc just for example):

require('child_process').exec('calc',
  function (error, stdout, stderr) {
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);
    if (error !== null) {
      console.log('exec error: ' + error);
    }
});

This will open calc, and stdout and stderr will log after I close it, which allows me to check the output and respond when the user closes the child process. But when I use elevate:

require('node-windows').elevate('calc',
  function (error, stdout, stderr) {
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);
    if (error !== null) {
      console.log('exec error: ' + error);
    }
});

Calc does indeed open with elevated privledges, but now stdout and stderr log immediately, I presume because it's aware of only the cmd or vbs, and not calc itself. This creates a problem, because now I can't check output or respond to the real close event.

I was hoping you had some thoughts to get around this issue.

Change service .exe publisher binary?

Service .EXE is compiled with a Publisher binary "CloudBees, Inc". How can I change it?
I checked js source code bit it seems I can't change it.. It looks as It is embedded into winsw.exe.

Thank you.

Unknown encoding

try run example on window 7 x86 non english localisation

buffer.js:440
throw new Error('Unknown encoding');
^
Error: Unknown encoding
at Buffer.toString (buffer.js:440:13)
at Object.fs.readFileSync (fs.js:236:33)
at Object.module.exports.createExe (c:\projects\example\node_modules\node-windows\lib\winsw.js:93:19)
at Object.defineProperties.install.value (c:\projects\example\node_modules\node-windows\lib\daemon.js:299:19)
at Object.oncomplete (fs.js:297:15)

Service doesn't restart after error

I am using windows server 2012 and have successfully create and run the service.
When my node application exit with error (in this case, database has query error), the *.err.log file correspond correctly, however the service doesn't restart itself. the service status is still running and it never stop.

I have edit my service properties like this:
----Recovery tab
-first failure, second failure, subsequent failure with restart the service
-reset fail count after 1 day
-reset service after 1 minutes
-enable actions for stops with error.

----Log On tab
allow service to interact with desktop

I have also change the daemon/*.exe properties to run as administrator and checked the user privilege with isAdminUser() and it returns that the user has administrative privileges.

on the service object, i use this attributes :
wait: 1,
grow: .25

is there something I miss ?

Feature Request: Restart on memory threshold.

Currently when an application running as a service runs out of memory the service does not restart, or show any sign of being stopped from the Windows Service Manager. It would be nice to be able to set a threshold on memory, where if reached the service would automatically restart.

Logging Error

There is an issue with the logging and node 0.0.10 on 64-bit systems. The event logging module is being replaced with an alternative that does not require building a native module.

Warning during call of "npm link node-windows"

I first did this:

npm install -g node-windows

And then I did this:

npm link node-windows

And received this warning:

npm WARN prefer global [email protected] should be installed with -g

Is it warning because it can't tell I installed 0.1.5 with -g? Or because there is actually a problem with how I installed it?

Cannot find module node-windows

Windows server 2012, followed instructions installed node-windows globally. when I run my install script I get "cannot find module node-windows". I had to install it locally in the folder with my script to get it to work.

The installation and usage instructions might need to be updated or more testing done, something is awry.

Stand-alone Service

I'm trying to look for a solution that can create a service for a node script and install it on any consumer computer.

So assuming the user doesn't have node.js installed on his/her machine. Can I still use this and run my script as a service?

Why daemon layer?

I'm using node-windows to register my nodejs application as service on win8. It works fine but I'm pretty curious that, why the launched "service" application have a daemon process?

I'm looking for a solution to have my app start on windows start, and restart when it crashed. So I register it as a service(using node-windows) but I find there're two nodejs launched: one daemon(wrapper.js), the other my app. Then I look into the source code and find that wrapper.js monitors my application.

So why node-windows don't have config to set up Recovery options of Windows service, but provide a daemon instead?

Node-schedule is not triggered.

I deployed my application as a service on Windows 8. The service was successfully deployed as localhost:8080 was up and running. In my app I have declared scheduled functions to run at specific times in day using node-schedule (https://www.npmjs.org/package/node-schedule). But these functions are not running at those times. For some reason, node-schedule function is not getting triggered. Here is my code:

var rule = new schedule.RecurrenceRule();
rule.dayOfWeek = [new schedule.Range(0, 6)];
rule.hour = [new schedule.Range(10, 22)]
rule.minute = [30];

var j = schedule.scheduleJob(rule, function() {
//do something
}

I used the barebone service.js

ReferenceError when executing sudo

A spell problem on lib/binariesjs:75 ahs been found while trying to execute the service as sudo.

ReferenceError: otions is not defined
at Object.module.exports.sudo (W:\Marina\MarinaWebView\WebView\node_modules\node-windows\lib\binaries.js:75:20)

It looks like it only needs a variable rename 'otions' -> 'options'

Error: Cannot find module 'node-windows'

Sorry, not sure if this a bug maybe more a question, apologies in advance. I followed the instructions for installing via npm, but when I try and run anything I just get the following error:

module.js:340
throw err;
^
Error: Cannot find module 'node-windows'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (F:\REngine\tools\node\services.js:1:76)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10

have also tried adding the path's to windows env. vars, adding the node-windows module to the project folder - same error? any help appreciated

execute command line code inside windows services

I want to execute "cmd" at the script (Ex: helloworled.js) inside windows services

cmd = path.join(__dirname,'sendInput.exe ') + input;
child = require('child_process').exec(cmd,
        function (error, stdout, stderr) {
            if (error !== null) {
                console.log('exec error: ' + error+'\n cmd: '+cmd);
                res.end("no");
            }else{
                console.log(input);
                res.end("ok");
            }

there is no error reporting but it is not executing the commend !!

event when i use "elevate" function like this

cmd = path.join(__dirname,'sendInput.exe ') + input;
child = require('node-windows').elevate(cmd,
        function (error, stdout, stderr) {
            if (error !== null) {
                console.log('exec error: ' + error+'\n cmd: '+cmd);
                res.end("no");
            }else{
                console.log(input);
                res.end("ok");
            }

the same issue

PS: tow above code snippets run correctly out of windows services

Question: where does console.log go?

Sorry to write this here, but I can't find where else I should write this question...

I have a node express app that I have installed as a service using node-windows.
But I cannot find where the console.log messages are going. Note, they are NOT going into the event logging.

Windows Server 2008 R2 uninstall method permission denied

Hello,

first of all thank you very much for such a useful extension! The installation process works fine, but I receive an error during the uninstall process.
unbenannt
I am running the script having administration rights and every file except for the "nodejswrapperforsolr.exe" file is removed. I also do not know if it is caused by the error, but the actual windows service also remains in the list of all windows services. I believe, that it has something to do with my operating system (Windows Server 2008 R2), because only the executable file stays untouched and causes the permission error.

Thank you in advice,
vrugaiti

Question: How to communicate with a service?

Say, I have a service that prints a message to the console every minute or so. How can I communicate with the service to change the message or make it reload its configuration file or something similar?

Option to set Startup Type on Service Install?

As the title suggests, I'm looking for a way to set the service "Startup Type" option when I install my service.. Is that possible with this package?

I had a look at the functionality from winsw.exe and I don't see it there, but just to confirm... Would this sort of option rely on a feature from winsw, or am I missing something simple here?

clean shutdown

There does not seem to be an event/signaling method that can be used for the service script to know when to shutdown. Thus a clean shutdown is not possible.

Any thoughts ? Did I overlook anything ?

Can't tell if elevate was successful

If I use wincmd.elevate() and a UAC prompt pops up, there doesn't seem to be a way to tell if the user declined the granting of permission. In the callback, the error, stdout, and stderr arguments are all empty.

Simple example is not working on Win7

I'm using following code:

// file install-as-service.js
var Service = require('node-windows').Service;
var package = require('./package.json');
var name = package.name;
var description = package.description;
var svc = new Service({
  name: name,
  description: description,
  script: "" + __dirname + "/index.js"
});

svc.on('install', function() {
  console.log('installed');
  return svc.start();
});

svc.on('error', function() {
  return console.log('error');
});

svc.on('alreadyinstalled', function() {
  return console.log('alreadyinstalled');
});

svc.install();
// file index.js
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

But when called node install-as-service.js I've got following error:

buffer.js:434
      throw new Error('Unknown encoding');
            ^
Error: Unknown encoding
    at Buffer.toString (buffer.js:434:13)
    at Object.fs.readFileSync (fs.js:236:33)
    at Object.module.exports.createExe (D:\git\test-server\node_modules\node-windows\lib\winsw.js:93:19)
    at Object.defineProperties.install.value (D:\git\test-server\node_modules\node-windows\lib\daemon.js:284:19)
    at Object.oncomplete (fs.js:297:15)

And when called again, output was:

alreadyinstalled

I don't see any testserver.exe file created under ./daemon, only testserver.xml file is here.

I'm using node version 0.8.10 and Win7 Professional SP1.

wrapper restart feature not working

I could not get the service to restart at all when my process died (using the default options.) I tested this by having my server purposefully throw an unhandled exception (and also by calling process.exit.) after some interval.

It seems the monitor function (in wrapper.js) assumes that if the child process emits an exit event then the !child.pid is true. Testing and logging showed this not to be the case (I'm using latest node release 0.10.25).

I modified your code, changing the exit handler to set child to null and changed the test in the monitor function to if(!child || !child.pid) and that seemed to fix it.

Again I'm not submitting a pull request at this point as I'm still waiting for your new release. Perhaps this is something you've already addressed? Also it would be very nice to have the event log messages that are created around restarts show some detail on the try number and wait amount.

Strip color codes in logs

Use the following code from the stripcolors module to prevent strange output in logs.

.replace(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/g, '')

Service name : remove ".exe" extension ?

Hello,

When I create a service, when I check its properties, I can see Service name : followed by a name with a .exe extension.
Could you remove the .exe extension ?

I think that the problem is in lib/daemon.js near

 _xml: {
enumerable: false,
get: function(){
return require('./winsw').generateXml({
name: this.name,
id: this._exe,

the line id: this._exe should be replaced with something like id: this.name or something similar (I am not sure about this.name, so do not copy/paste my suggestion before thinking about the consequences on the service !)

Regards,
Yves

NODE_ENV - how to set it?

Hi,

Great module, but how do I set f.ex. NODE_ENV=production?

Normally on windows you do it on the commandline with SET NODE_ENV=production, but I can not figure out how to do it with this module.

Thanks

Question: Server restart - A way of starting the services, in a particular order?

This is a questions, rather than an issue.
I've only taken a look and done some basic stuff with it, but it looks great - thanks for your hardwork. Especially like the eventlogger.

The Questions

If the server has to restarted, is there a way of saying start this service first, then this one or these sets of services?

I'm thinking around, something like Seaport (by Substack), where I need to start the seaport server first, then any services that need to register with it.

It might be out of the scope of this module, but I'd be interested to hear your thoughts.

Unlinking exe file fails on installation

I just noticed that the service uninstallation has trouble unlinking the exe file on my machine. This may be user error, in which case I apologize.

fs.js:760
  return binding.unlink(pathModule._makeLong(path));
                 ^
Error: EPERM, operation not permitted 'C:\Users\pschuegr\Documents\GitHub\wt\package\daemon\wt.exe'
    at Object.fs.unlinkSync (fs.js:760:18)
    at rm (C:\Users\pschuegr\AppData\Roaming\npm\node_modules\node-windows\lib\daemon.js:458:22)
    at C:\Users\pschuegr\AppData\Roaming\npm\node_modules\node-windows\lib\daemon.js:471:15
    at ChildProcess.exithandler (child_process.js:635:7)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:735:16)
    at Socket.<anonymous> (child_process.js:948:11)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Pipe.close (net.js:466:12)
npm ERR! weird error 8
npm ERR! not ok code 0

no way to specify service logon info

Thanks for this elegant module. One thing that threw me while reading the doc is the user attribute. I assumed it was transferred over to the service logon information on the installed service, but it's not. Instead it's just the user account used to run the service setup command.

That being said, having the ability to programattically specify the service logon credentials is something I really need. Why not create another set of credentials in the config for that? It looks like it would be a quite simple modification, given that winsw supports this (under the serviceaccount xml attribute.)

One potential security issue is that the user account and password are placed in clear text in the xml file, so if this is done perhaps there would be a post install hook that munges the password in xml?

(P.S. Also, this is minor, but would be great if generateXml created xml that was formatted nicely for readability.)

The main executable is missing or cannot be found

Hello,

When I was trying to run the example code on my Windows 7 machine, I run into this error. I've spent some time trying to figure out the solution but no luck....

$node install

C:\myDirectory\node_modules\node-windows\lib\daemon.js:266
n<'The main executable is missing or cannot be found <`+path.join<me.root,this

TypeError: Cannot ready property 'root'of undefined
at Object.defineProperties.install.value [as install] <C:\myDirectory\node_modules\node-windows\lib\daemon.js:266:93>
at Object.

Events not getting logged within context of a service on Windows XP

For some reason, the script belowadds events to the event log under windows xp in a command prompt window but not when running as a service. The service executable seems to be able to write to the event log indicating stop/start of the service, just not the script.

I've tested this on Windows 7 and it works as expected.

var windows = require('node-windows');
var EventLogger = windows.EventLogger;
var eventLogger = new EventLogger({source: 'My Application'});
eventLogger.info('An Informational message');

var http = require('http');
var server = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
//res.end(JSON.stringify(process.env));
res.end('Hello World\n');
});

server.listen(3000, '127.0.0.1');
console.log('Server running at http://127.0.0.1:3000/');

// Force the process to close after 15 seconds
/*setTimeout(function(){
process.exit();
},15000);
*/

windows cannot find rmdir

I'm taking a copy of the example folder and running it verbatim (after fixing the require paths at the top). Installation works fine. After waiting a few minutes, the attempt to uninstall gives me a popup saying "windows cannot find rmdir." After I exit that popup, the console spits:

Uninstall complete.
The service exists:  true

And consequent attempts to install say:

This service is already installed.

Even though the files are being removed, the daemon directory remains, causing the glitch. If I remove the directory I am able to install again.

Running npm or coffee as command.

Hi there, this is a really cool package and I'd like to use it, BUT I have some issues. First is that the two ways I can start my node.js app are: coffee app.coffee and npm start. As far as I can tell neither of these is supported.

I understand the first is probably a little out of scope for this project but the second - running npm scripts would be useful.

Any chance of that making it in at some point?

Description not working

The description doesn't show in the windows Services pane.
OS: Win7
Node version: v0.10.20

Code

/*
 * Installs Resity application as a windows service
 */
var Service = require('node-windows').Service

/*
 * Create a new service object
 */
var svc = new Service({
     name:'todo'
  ,  description: 'Insert Description here'
  ,  script: process.cwd() + '/index.js'
})

/*
 * Listen for the "install" event, indicating the process is available as a service.
 */
svc.on ('install', function () {
  svc.start ()
})

svc.on ('uninstall', function () {
  console.log ('uninstalled')
  svc.install()
})

svc.on ('alreadyinstalled', function () {
  console.warn ('already installed')
  svc.uninstall()
})

svc.on ('invalidinstallation', function () {
  console.warn ('invalid installation')
})

svc.on ('start', function () {
  console.log ('service started')
})

svc.on ('stop', function () {
  console.log ('service stopped')
})

svc.on ('error', function (err) {
  console.error (err)
})

svc.install ()
// svc.uninstall ()

Services (screen-shot)
service

EventLogger ignores source name defined in constructor

I'm using EventLogger for logging in my app, but all my logs have source set to "Node.js" instead of string which I defined in EventLogger constructor.

For example:
var EventLogger = require('node-windows').EventLogger;
var log = new EventLogger('TestLogger');
log.info('Test');

creates log in Windows Logs / Application with source "Node.js" instead of "TestLogger"

My Node.js version: 0.10.27,
OS: Windows 8.1 x64

Helloworld example failure

Here is what I get when uninstalling the Helloworld example service...

D:\TekiaDev\Apps\TopicSpace\node_modules\node-windows\example>node uninstall

fs.js:760
return binding.unlink(pathModule._makeLong(path));
^
Error: EBUSY, resource busy or locked 'D:\TekiaDev\Apps\TopicSpace\node_modules\node-windows\example\d
aemon\helloworld.out.log'
at Object.fs.unlinkSync (fs.js:760:18)
at rm (D:\TekiaDev\Apps\TopicSpace\node_modules\node-windows\lib\daemon.js:458:22)
at D:\TekiaDev\Apps\TopicSpace\node_modules\node-windows\lib\daemon.js:467:15
at ChildProcess.exithandler (child_process.js:603:7)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:703:16)
at Socket. (child_process.js:916:11)
at Socket.EventEmitter.emit (events.js:95:17)
at Pipe.close (net.js:451:12)

The ./daemon/xml and ./daemon/wrapper get deleted ok however.

I get the same behavior with my service application.

Tks.

Unknown encoding error

When I try to run a basic service by using the same code from the demo:
var Service = require('node-windows').Service;

// Create a new service object
var svc = new Service({
  name:'WeaveAgent',
  description: 'The nodejs.org example web server.',
  script: require('path').join(__dirname,'lib/weave-agent.js')
});

// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function(){
  svc.start();
});

svc.install();

I get a weird 'unknown' encoding error':
screen shot 2013-07-23 at 3 09 50 pm

OS: Windows XP

Creating `winsw.exe.config` is required to run winws.exe under .NET 4.0 runtime

Is there any chance to put app.exe.config to daemon dir something like this?

var svc = new Service({
  name:'Hello World',
  description: 'The nodejs.org example web server.',
  script: 'C:\\path\\to\\helloworld.js',
  supportedRuntime: ['v2.0.50727', 'v4.0]
});

or

svn.on('beforeInstall', function () {
    // creates .exe.config
});

https://github.com/kohsuke/winsw#net-runtime-40

Newer versions of Windows (confirmed on Windows Server 2012, possibly with Windows 8, too) do not ship with .NET runtime 2.0, which is what winsw.exe is built against. This is because unlike Java, where a newer runtime can host apps developed against earlier runtime, .NET apps need version specific runtimes.

One way to deal with this is to ensure that .NET 2.0 runtime is installed through your installer, but another way is to declare that winsw.exe can be hosted on .NET 4.0 runtime by creating an app config file winsw.exe.config.

<configuration>
  <startup>
    <supportedRuntime version="v2.0.50727" />
    <supportedRuntime version="v4.0" />
  </startup>
</configuration>

Permission denied on Windows 7

There's an issue with the isAdminUser method that is preventing some users from ever receiving a true value, even when they are an admin. Issue is already fixed for the next release.

EventLogger not picking up string argument

Specifying a string argument to EventLogger implicitly creates a config object as follows:
config = {name: }

However, when you initialize the logger's source property from the config object, you look for config.source. Consequently we always end up with 'Node.js' (the default) as the log source.

Tks!

Node process is not terminated on service stop

When the service is stopped the wrapper process is detached and keeps running.
In my case the wrapper process spawns 2 child processes one node and one mongodb.
I have to terminate the process manually to restart the service.

I'm running windows 7 32 bits.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.