|
| 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