diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 019e8b5025..e8804ad333 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -770,6 +770,7 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam * [:link:](websocket/websocket.d.ts) [websocket](https://github.com/Worlize/WebSocket-Node) by [Paul Loyd](https://github.com/loyd) * [:link:](when/when.d.ts) [When](https://github.com/cujojs/when) by [Derek Cicerone](https://github.com/derekcicerone), [Wim Looman](https://github.com/Nemo157) * [:link:](which/which.d.ts) [which](https://github.com/isaacs/node-which) by [vvakame](https://github.com/vvakame) +* [:link:](windows-service/windows-service.d.ts) [windows-service](https://bitbucket.org/stephenwvickers/node-windows-service) by [rogierschouten](https://github.com/rogierschouten) * [:link:](winjs/winjs.d.ts) [WinJS](http://try.buildwinjs.com) by [TypeScript samples](https://www.typescriptlang.org), [Adam Hewitt](https://github.com/adamhewitt627), [Craig Treasure](https://github.com/craigktreasure), [Jeff Fisher](https://github.com/xirzec) * [:link:](winrt/winrt.d.ts) [WinRT](http://msdn.microsoft.com/en-us/library/windows/apps/br211377.aspx) by [TypeScript samples](https://www.typescriptlang.org) * [:link:](winston/winston.d.ts) [winston](https://github.com/flatiron/winston) by [bonnici](https://github.com/bonnici), [Peter Harris](https://github.com/codeanimal) diff --git a/windows-service/windows-service-tests.ts b/windows-service/windows-service-tests.ts new file mode 100644 index 0000000000..667a343d91 --- /dev/null +++ b/windows-service/windows-service-tests.ts @@ -0,0 +1,21 @@ +/// + +import stream = require("stream"); +import service = require("windows-service"); + +service.add("MyService"); +service.add("MyService", {programPath: "./service.js"}); + +var s: stream.Writable; +var t: stream.Writable; + +service.run(s, (): void => { + service.stop(0); +}); + +service.run(s, t, (): void => { + service.stop(0); +}); + +service.remove("MyService"); + diff --git a/windows-service/windows-service.d.ts b/windows-service/windows-service.d.ts new file mode 100644 index 0000000000..a116663191 --- /dev/null +++ b/windows-service/windows-service.d.ts @@ -0,0 +1,74 @@ +// Type definitions for windows-service 1.0.4 +// Project: https://bitbucket.org/stephenwvickers/node-windows-service +// Definitions by: Rogier Schouten +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// +declare module "windows-service" { + import stream = require("stream"); + + /** + * Options for the add() function. + */ + export interface AddOptions { + /** + * The services display name, defaults to the name parameter + */ + displayName?: string; + /** + * The fully qualified path to the node binary used to run the service (i.e. c:\Program Files\nodejs\node.exe, defaults to the value of process.execPath + */ + nodePath?: string; + /** + * An array of strings specifying parameters to pass to nodePath, defaults to [] + */ + nodeArgs?: string[]; + /** + * The program to run using nodePath, defaults to the value of process.argv[1] + */ + programPath?: string; + /** + * An array of strings specifying parameters to pass to programPath, defaults to [] + */ + programArgs?: string[]; + } + + /** + * The add() function adds a Windows service. The service will be set to automatically start at boot time, but not started. + * The service can be started using the net start "My Service" command. An exception will be thrown if the service could + * not be added. The error will be an instance of the Error class. + * + * @param name The name parameter specifies the name of the created service. + * @param opts Options + */ + export function add(name: string, opts?: AddOptions): void; + + + /** + * The remove() function removes a Windows service. + * The name parameter specifies the name of the service to remove. This will be the same name parameter specified when adding the service. + * The service must be in a stopped state for it to be removed. The net stop "My Service" command can be used to stop the service before + * it is to be removed. + * An exception will be thrown if the service could not be removed. The error will be an instance of the Error class. + */ + export function remove(name: string): void; + + /** + * The run() function will connect the calling program to the Windows Service Control Manager, allowing the program to run as a Windows service. + * The programs process.stdout stream will be replaced with the stdoutLogStream parameter, and the programs process.stderr stream replaced with + * the stdoutLogStream parameter (this allows the redirection of all console.log() type calls to a service specific log file). If the stderrLogStream + * parameter is not specified the programs process.stderr stream will be replaced with the stdoutLogStream parameter. The callback function will be + * called when the service receives a stop request, e.g. because the Windows Service Controller was used to send a stop request to the service. + * The program should perform cleanup tasks and then call the service.stop() function. + */ + export function run(stdoutLogStream: stream.Writable, callback: () => void): void; + export function run(stdoutLogStream: stream.Writable, stderrLogStream: stream.Writable, callback: () => void): void; + + /** + * The stop() function will cause the service to stop, and the calling program to exit. + * Once the service has been stopped this function will terminate the program by calling the process.exit() function, passing to it the rcode + * parameter which defaults to 0. Before calling this function ensure the program has finished performing cleanup tasks. + * BE AWARE, THIS FUNCTION WILL NOT RETURN. + */ + export function stop(rcode?: number): void; +}