coreybutler / node-windows

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

Start service but after a few seconds fall down #251

Closed raullb34 closed 4 years ago

raullb34 commented 4 years ago

Hi I'm trying to create many services in windows, a few work, and the others don't. This is an api service, that starts and a sencond later stop, I don't know why? Could anybody help me? Tnx.

var svcApi = new Service({ name:'API Service', description: 'API Services', script: 'C:\\Users\\User\\Documents\\APIS\\server.js', /*nodeOptions: [ '--harmony', '--max_old_space_size=4096' ],*/ //execPath:'C:\\ Program\ Files\\ nodejs\\ node.exe', wait: 2 });

var ApiLog = new EventLogger({source: 'Log API',eventLog: 'SYSTEM'});

svcApi.on('install',function(){ console.log('Se ha instalado el servicio'); ApiLog.info('El servicio se ha instalado'); svcTr.start(); }); svcApi.on('error',function(err){ console.log('Ha habido un error con el servicio '+err); ApiLog.error('El servicio ha fallado '+err); svcTr.start(); }); svcApi.on('stop',function(stop){ console.log('Se ha parado el sevicio '+stop); ApiLog.warn('El servicio se ha parado'); svcTr.start(); }); svcApi.on('start',function(){ console.log('Se ha inciado correctamente el servicio'); ApiLog.warn('El servicio se ha iniciado'); }); node-windows version 6.12.0 node version v12.13.0 Windows 10.

Lijinghan9611 commented 4 years ago

win+x, use 'window powershell(admin)'

coreybutler commented 4 years ago

This could be happening for any number of reasons, but it's very unlikely this is something caused by node-windows. It is usually due to something in your script.

The most common reason for this experience is the service will launch, and the script attempts to launch a web server that is misconfigured. It usually has to do with referencing a path or a port.

Make sure you've reviewed the wiki, and pay special attention to any uses of __dirpath, __filepath, or require('xxxxx.json') statements.

Remember, Windows requires higher level permissions to run servers on ports below 1024. So, if you're trying to install a service running on port 80 with an unprivileged/underprivileged account, it will likely fail.

raullb34 commented 4 years ago

Thanks for the response, my problem was with the working directory, beacause I was installed node-windows in a previous directory and the execution of the script wasn´t working, that was the reason, I close the issue.

coreybutler commented 4 years ago

For anyone who finds this via Google, please see My script installs, but stops after a few seconds. Why?