Skip to content

Commit

Permalink
ncm-chkconfig: add chkconfig function to enable/disable services
Browse files Browse the repository at this point in the history
  • Loading branch information
stdweird committed Aug 10, 2017
1 parent c34d49b commit 479dc3c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
20 changes: 1 addition & 19 deletions ncm-chkconfig/src/main/pan/components/chkconfig/config.pan
Original file line number Diff line number Diff line change
@@ -1,19 +1 @@
# ${license-info}
# ${developer-info}
# ${author-info}
# ${build-info}

unique template components/${project.artifactId}/config;

include 'components/${project.artifactId}/schema';

bind "/software/components/${project.artifactId}" = component_chkconfig_type;

# Set prefix to root of component configuration.
prefix '/software/components/${project.artifactId}';
'active' ?= true;
'dispatch' ?= true;
'dependencies/pre' ?= list("spma");

# Package to install
"/software/packages" = pkg_repl("ncm-${project.artifactId}", "${no-snapshot-version}-${rpm.release}", "noarch");
${componentconfig}
25 changes: 19 additions & 6 deletions ncm-chkconfig/src/main/pan/components/chkconfig/schema.pan
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# ${license-info}
# ${developer-info}
# ${author-info}

declaration template components/chkconfig/schema;
${componentschema}

include 'quattor/types/component';

Expand Down Expand Up @@ -37,6 +33,23 @@ function chkconfig_allow_combinations = {
true;
};

@{Enables (on + startstop=true) all arguments as services.
If argument starts with a -, it is disabled (off + startstop=true).
Use as e.g.
"/software/components" = chkconfig("service1", "-service2");
}
function chkconfig = {
foreach (idx;arg;ARGV) {
m = matches(arg, '^(-)?(.*)$');
what = 'on';
if (m[1] == '-') {
what = 'off';
};
SELF['chkconfig']['service'][escape(m[2])] = dict(what, '', 'startstop', true);
};
SELF;
};

type service_type = {
"name" ? string
"add" ? boolean
Expand All @@ -47,7 +60,7 @@ type service_type = {
"startstop" ? boolean
} with chkconfig_allow_combinations(SELF);

type component_chkconfig_type = {
type ${project.artifactId}_component = {
include structure_component
"service" : service_type{}
"default" ? string with match (SELF, '^(ignore|off)$')
Expand Down
6 changes: 6 additions & 0 deletions ncm-chkconfig/src/test/perl/component.t
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,11 @@ isa_ok($cmd, "CAF::Process", "Command for service --del test_del (off first) run
$cmd = get_command("/sbin/chkconfig --del test_del")->{object};
isa_ok($cmd, "CAF::Process", "Command for service --del test_del run");

is_deeply($cfg->getTree("/software/components/chkconfig/service/{test_enable}"),
{'on', '', 'startstop', 1},
'chkconfig function creates correct enabled service');
is_deeply($cfg->getTree("/software/components/chkconfig/service/{test_disable}"),
{'off', '', 'startstop', 1},
'chkconfig function creates correct disabled service');

done_testing();
3 changes: 3 additions & 0 deletions ncm-chkconfig/src/test/resources/simple_services.pan
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ prefix "/software/components/chkconfig/service";
# the service has to exists and/or turned on
"{test_off}" = dict("off","45");
"{test_del}" = dict("del",true,);

# test function
"/software/components" = chkconfig("test_enable", "-test_disable");

0 comments on commit 479dc3c

Please sign in to comment.