Skip to content

Commit 0d7a9a4

Browse files
committed
Merge pull request DefinitelyTyped#3715 from rogierschouten/windows-service
Add typings for windows-service
2 parents 4d8b044 + d32418b commit 0d7a9a4

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam
771771
* [:link:](websocket/websocket.d.ts) [websocket](https://github.com/Worlize/WebSocket-Node) by [Paul Loyd](https://github.com/loyd)
772772
* [:link:](when/when.d.ts) [When](https://github.com/cujojs/when) by [Derek Cicerone](https://github.com/derekcicerone), [Wim Looman](https://github.com/Nemo157)
773773
* [:link:](which/which.d.ts) [which](https://github.com/isaacs/node-which) by [vvakame](https://github.com/vvakame)
774+
* [:link:](windows-service/windows-service.d.ts) [windows-service](https://bitbucket.org/stephenwvickers/node-windows-service) by [rogierschouten](https://github.com/rogierschouten)
774775
* [: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)
775776
* [:link:](winrt/winrt.d.ts) [WinRT](http://msdn.microsoft.com/en-us/library/windows/apps/br211377.aspx) by [TypeScript samples](https://www.typescriptlang.org)
776777
* [:link:](winston/winston.d.ts) [winston](https://github.com/flatiron/winston) by [bonnici](https://github.com/bonnici), [Peter Harris](https://github.com/codeanimal)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path="windows-service.d.ts" />
2+
3+
import stream = require("stream");
4+
import service = require("windows-service");
5+
6+
service.add("MyService");
7+
service.add("MyService", {programPath: "./service.js"});
8+
9+
var s: stream.Writable;
10+
var t: stream.Writable;
11+
12+
service.run(s, (): void => {
13+
service.stop(0);
14+
});
15+
16+
service.run(s, t, (): void => {
17+
service.stop(0);
18+
});
19+
20+
service.remove("MyService");
21+

windows-service/windows-service.d.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Type definitions for windows-service 1.0.4
2+
// Project: https://bitbucket.org/stephenwvickers/node-windows-service
3+
// Definitions by: Rogier Schouten <https://github.com/rogierschouten>
4+
// Definitions: https://github.com/borisyankov/DefinitelyTyped
5+
6+
/// <reference path="../node/node.d.ts" />
7+
declare module "windows-service" {
8+
import stream = require("stream");
9+
10+
/**
11+
* Options for the add() function.
12+
*/
13+
export interface AddOptions {
14+
/**
15+
* The services display name, defaults to the name parameter
16+
*/
17+
displayName?: string;
18+
/**
19+
* 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
20+
*/
21+
nodePath?: string;
22+
/**
23+
* An array of strings specifying parameters to pass to nodePath, defaults to []
24+
*/
25+
nodeArgs?: string[];
26+
/**
27+
* The program to run using nodePath, defaults to the value of process.argv[1]
28+
*/
29+
programPath?: string;
30+
/**
31+
* An array of strings specifying parameters to pass to programPath, defaults to []
32+
*/
33+
programArgs?: string[];
34+
}
35+
36+
/**
37+
* The add() function adds a Windows service. The service will be set to automatically start at boot time, but not started.
38+
* The service can be started using the net start "My Service" command. An exception will be thrown if the service could
39+
* not be added. The error will be an instance of the Error class.
40+
*
41+
* @param name The name parameter specifies the name of the created service.
42+
* @param opts Options
43+
*/
44+
export function add(name: string, opts?: AddOptions): void;
45+
46+
47+
/**
48+
* The remove() function removes a Windows service.
49+
* The name parameter specifies the name of the service to remove. This will be the same name parameter specified when adding the service.
50+
* 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
51+
* it is to be removed.
52+
* An exception will be thrown if the service could not be removed. The error will be an instance of the Error class.
53+
*/
54+
export function remove(name: string): void;
55+
56+
/**
57+
* The run() function will connect the calling program to the Windows Service Control Manager, allowing the program to run as a Windows service.
58+
* The programs process.stdout stream will be replaced with the stdoutLogStream parameter, and the programs process.stderr stream replaced with
59+
* the stdoutLogStream parameter (this allows the redirection of all console.log() type calls to a service specific log file). If the stderrLogStream
60+
* parameter is not specified the programs process.stderr stream will be replaced with the stdoutLogStream parameter. The callback function will be
61+
* 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.
62+
* The program should perform cleanup tasks and then call the service.stop() function.
63+
*/
64+
export function run(stdoutLogStream: stream.Writable, callback: () => void): void;
65+
export function run(stdoutLogStream: stream.Writable, stderrLogStream: stream.Writable, callback: () => void): void;
66+
67+
/**
68+
* The stop() function will cause the service to stop, and the calling program to exit.
69+
* Once the service has been stopped this function will terminate the program by calling the process.exit() function, passing to it the rcode
70+
* parameter which defaults to 0. Before calling this function ensure the program has finished performing cleanup tasks.
71+
* BE AWARE, THIS FUNCTION WILL NOT RETURN.
72+
*/
73+
export function stop(rcode?: number): void;
74+
}

0 commit comments

Comments
 (0)