coreybutler / node-windows

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

service.start() doesn't start the service #137

Closed wkentdag closed 8 years ago

wkentdag commented 8 years ago

I'm new to windows / service development so I'm not entirely sure whether this is a bug in the library or user error, but here's my situation: I'm using code lifted from example/index.js in this repo:

// service.js
const Service = require('node-windows').Service
const path = require('path')

const service = new Service({
  name: process.env.HOST_NICKNAME,
  description: process.env.HOST_DESCRIPTION,
  script: path.join(__dirname, 'index.js')
})

service.on('install', () => {
  service.start()
})

service.on('start', () => {
  console.log(`${service.name} started!`)
})

module.exports = service

I run npm start, which fires the following script:

// scripts\index.js
require('dotenv').config({silent: true})
const service = require('../lib/service.js')

// Install the service
service.install()

...and produces the following output, which would appear to indicate that the service is installed and started:

C:\Users\will\code\secure-key-fingerprint>npm start

> secure-key-fingerprint@0.0.1 start C:\Users\will\code\secure-key-fingerprint
> node scripts\install.js

secure key started!

C:\Users\will\code\secure-key-fingerprint>

However, when I navigate to the Services app, it shows the service installed but idling, not running, and I have to manually start the service through the GUI: service-installed-but-stopped

Here's my specs:

coreybutler commented 8 years ago

There's no bug in the library, but there is a problem in the example. The script attribute should be an absolute path, not __dirname. The path is changing from when it runs as a daemon compared to when it runs without the daemon.

wkentdag commented 8 years ago

👍 thanks for clarifying!