Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify a description when adding a service #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions example/periodic-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var fs = require ("fs");
var service = require ("../");

function usage () {
console.log ("usage: node periodic-logger --add <name> [username] [password] [dep dep ...]");
console.log ("usage: node periodic-logger --add <name> [description] [username] [password] [dep dep ...]");
console.log (" node periodic-logger --remove <name>");
console.log (" node periodic-logger --run");
process.exit (-1);
Expand All @@ -20,13 +20,16 @@ if (process.argv[2] == "--add" && process.argv.length >= 4) {
};

if (process.argv.length > 4)
options.username = process.argv[4];
options.description = process.argv[4];

if (process.argv.length > 5)
options.password = process.argv[5];
options.username = process.argv[5];

if (process.argv.length > 6)
options.dependencies = process.argv.splice(6);
options.password = process.argv[6];

if (process.argv.length > 7)
options.dependencies = process.argv.splice(7);

service.add (process.argv[3], options, function(error) {
if (error)
Expand Down
17 changes: 13 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ var linuxStartStopScript = [
'# Default-Start: ##RUN_LEVELS_ARR##',
'# Default-Stop: 0 1 6',
'# Short-Description: Start ##NAME## at boot time',
'# Description: Enable ##NAME## service.',
'# Description: ##DESCRIPTION##',
'### END INIT INFO',
'',
'# chkconfig: ##RUN_LEVELS_STR## 99 1',
'# description: ##NAME##',
'# description: ##DESCRIPTION##',
'',
'umask 0007',
'',
Expand Down Expand Up @@ -143,7 +143,7 @@ var linuxStartStopScript = [

var linuxSystemUnit = [
'[Unit]',
'Description=##NAME##',
'Description=##DESCRIPTION##',
'After=network.target',
'Requires=##DEPENDENCIES##',
'',
Expand Down Expand Up @@ -203,10 +203,14 @@ function add (name, options, cb) {
var username = options ? (options.username || null) : null;
var password = options ? (options.password || null) : null;


if (os.platform() == "win32") {
var displayName = (options && options.displayName)
? options.displayName
: name;
var description = (options && options.description)
? options.description
: "Enable " + displayName + " service.";

var serviceArgs = [];

Expand All @@ -233,12 +237,15 @@ function add (name, options, cb) {

try {
getServiceWrap ().add (name, displayName, servicePath, username,
password, deps);
password, deps, description);
cb();
} catch (error) {
cb(error);
}
} else {
var description = (options && options.description)
? options.description
: "Enable " + name + " service.";
var nodeArgs = [];
if (options && options.nodeArgs)
for (var i = 0; i < options.nodeArgs.length; i++)
Expand Down Expand Up @@ -275,6 +282,7 @@ function add (name, options, cb) {
var line = linuxStartStopScript[i];

line = line.replace("##NAME##", name);
line = line.replace("##DESCRIPTION##", description);
line = line.replace("##NODE_PATH##", nodePath);
line = line.replace("##NODE_ARGS##", nodeArgsStr);
line = line.replace("##PROGRAM_PATH##", programPath);
Expand Down Expand Up @@ -325,6 +333,7 @@ function add (name, options, cb) {
var line = linuxSystemUnit[i];

line = line.replace("##NAME##", name);
line = line.replace("##DESCRIPTION##", description);
line = line.replace("##NODE_PATH##", nodePath);
line = line.replace("##NODE_ARGS##", nodeArgsStr);
line = line.replace("##PROGRAM_PATH##", programPath);
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"dependencies": {
"nan": "2.3.x"
},
"contributors": [
"contributors": [
{
"name": "Stephen Vickers",
"email": "[email protected]"
}
}
],
"repository": {
"type": "git",
Expand All @@ -26,9 +26,9 @@
"linux-daemon",
"linux-service",
"service",
"windows",
"windows-daemon",
"windows-service"
"windows",
"windows-daemon",
"windows-service"
],
"author": "Stephen Vickers <[email protected]>",
"license": "MIT"
Expand Down
20 changes: 20 additions & 0 deletions src/service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,26 @@ NAN_METHOD(Add) {
return;
}

char* description = NULL;
if (info.Length() > 6) {
if (info[6]->IsString ()) {
Nan::Utf8String tmp_description(info[6]);
description = *tmp_description;
}
}
SERVICE_DESCRIPTION description_struct;
description_struct.lpDescription = description;

if (! ChangeServiceConfig2 (svc_handle, SERVICE_CONFIG_DESCRIPTION,
&description_struct)) {
std::string message ("ChangeServiceConfig2() failed: ");
message += raw_strerror (GetLastError ());
CloseServiceHandle (scm_handle);
Nan::ThrowError(message.c_str());
return;
}


CloseServiceHandle (svc_handle);
CloseServiceHandle (scm_handle);

Expand Down