Skip to content

Commit

Permalink
Merge pull request #1789 from jrha/cleanup-systemd
Browse files Browse the repository at this point in the history
ncm-systemd: Cleanup pan templates
  • Loading branch information
jrha authored Dec 16, 2024
2 parents f82ef3d + 94e28b5 commit a1051d5
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 52 deletions.
2 changes: 1 addition & 1 deletion ncm-systemd/src/main/pan/components/systemd/functions.pan
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ unique template components/${project.artifactId}/functions;
}
function systemd_make_mountunit = {
if (ARGC != 1) {
error(format("systemd_make_mountunit takes exactly one argument, got %s", ARGC));
error("systemd_make_mountunit takes exactly one argument, got %s", ARGC);
};
if (ARGV[0] == '/') {
error("systemd_make_mountunit cannot convert /");
Expand Down
30 changes: 19 additions & 11 deletions ncm-systemd/src/main/pan/components/systemd/schema.pan
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ type hwloc_location = string with match(SELF, '^[\w:.]+$');
syslog facility to use when logging to syslog
}
type syslog_facility = string with match(SELF,
'^(kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|authpriv|ftp|local[0-7])$');
'^(kern|user|mail|daemon|auth|syslog|lprnews|uucp|cron|authpriv|ftp|local[0-7])$'
);

@documentation{
syslog level to use when logging to syslog or the kernel log buffer
Expand All @@ -30,13 +31,15 @@ type ${project.artifactId}_skip = {

type ${project.artifactId}_unit_architecture = string with match(SELF,
'^(native|x86(-64)?|ppc(64)?(-le)?|ia64|parisc(64)?|s390x?|sparc(64)?)' +
'|mips(-le)?|alpha|arm(64)?(-be)?|sh(64)?|m86k|tilegx|cris$');
'|mips(-le)?|alpha|arm(64)?(-be)?|sh(64)?|m86k|tilegx|cris$'
);

type ${project.artifactId}_unit_security = string with match(SELF, '^!?(selinux|apparmor|ima|smack|audit)$');

type ${project.artifactId}_unit_virtualization = string with match(SELF,
'^(0|1|vm|container|qemu|kvm|zvm|vmware|microsoft|oracle|xen' +
'|bochs|uml|openvz|lxc(-libvirt)?|systemd-nspawn|docker)$');
'|bochs|uml|openvz|lxc(-libvirt)?|systemd-nspawn|docker)$'
);

# TODO: https://github.com/quattor/configuration-modules-core/issues/646:
# make this more finegrained, e.g. has to be existing unit; or check types
Expand Down Expand Up @@ -120,7 +123,8 @@ type ${project.artifactId}_unitfile_config_unit = {
'NetClass' ? string
'OnFailure' ? string[]
'OnFailureJobMode' ? string with match(SELF,
'^(fail|replace(-irreversibly)?|isolate|flush|ignore-(dependencies|requirements))$')
'^(fail|replace(-irreversibly)?|isolate|flush|ignore-(dependencies|requirements))$'
)
'PartOf' ? ${project.artifactId}_valid_unit[]
'PropagatesReloadTo' ? string[]
'RefuseManualStart' ? boolean
Expand Down Expand Up @@ -149,7 +153,8 @@ type ${project.artifactId}_unitfile_config_install = {
};

type ${project.artifactId}_unitfile_config_systemd_exec_stdouterr = string with match(SELF,
'^(inherit|null|tty|journal|syslog|kmsg|journal+console|syslog+console|kmsg+console|socket)$');
'^(inherit|null|tty|journal|syslog|kmsg|journal+console|syslog+console|kmsg+console|socket)$'
);

@documentation{
systemd.kill directives
Expand All @@ -159,7 +164,8 @@ valid for [Service], [Socket], [Mount], or [Swap] sections
type ${project.artifactId}_unitfile_config_systemd_kill = {
'KillMode' ? string with match(SELF, '^(control-group|process|mixed|none)$')
'KillSignal' ? string with match(SELF,
'^SIG(HUP|INT|QUIT|ILL|ABRT|FPE|KILL|SEGV|PIPE|ALRM|TERM|USR[12]|CHLD|CONT|STOP|T(STP|TIN|TOU))$')
'^SIG(HUP|INT|QUIT|ILL|ABRT|FPE|KILL|SEGV|PIPE|ALRM|TERM|USR[12]|CHLD|CONT|STOP|T(STP|TIN|TOU))$'
)
'SendSIGHUP' ? boolean
'SendSIGKILL' ? boolean
};
Expand Down Expand Up @@ -190,7 +196,7 @@ type ${project.artifactId}_unitfile_config_systemd_exec = {
'LimitFSIZE' ? long(-1..) # The maximum size of files that the process may create
'LimitLOCKS' ? long(-1..) # (Early Linux 2.4 only) A limit on the number of locks
'LimitMEMLOCK' ? long(-1..) # The maximum number of bytes of memory that may be locked into RAM
'LimitMSGQUEUE' ? long(-1..) # pecifies the limit on the number of bytes that can be allocated for POSIX message queues for the real user ID of the calling process.
'LimitMSGQUEUE' ? long(-1..) # Specifies the limit on the number of bytes that can be allocated for POSIX message queues for the real user ID of the calling process.
'LimitNICE' ? long(0..40) # Specifies a ceiling to which the process's nice value can be raised. The actual ceiling for the nice value is calculated as 20 - rlim_cur.
'LimitNOFILE' ? long(-1..) # Specifies a value one greater than the maximum file descriptor number that can be opened by this process.
'LimitNPROC' ? long(-1..) # The maximum number of processes (or, more precisely on Linux, threads) that can be created for the real user ID of the calling process.
Expand Down Expand Up @@ -228,11 +234,13 @@ type ${project.artifactId}_unitfile_config_systemd_exec = {
'WorkingDirectory' ? string
};

type ${project.artifactId}_unitfile_config_systemd_resource_control_devicelist = string[] with length(SELF) == 2 &&
match(SELF[0], '^(char-|block-|/dev/)') && match(SELF[1], '^[rwm]{1,3}$');
type ${project.artifactId}_unitfile_config_systemd_resource_control_devicelist = string[] with {
length(SELF) == 2 && match(SELF[0], '^(char-|block-|/dev/)') && match(SELF[1], '^[rwm]{1,3}$')
};

type ${project.artifactId}_unitfile_config_systemd_resource_control_block_weight = string[] with length(SELF) == 2 &&
match(SELF[0], '^/') && match(SELF[1], '^[0-9]+$');
type ${project.artifactId}_unitfile_config_systemd_resource_control_block_weight = string[] with {
length(SELF) == 2 && match(SELF[0], '^/') && match(SELF[1], '^[0-9]+$')
};

@documentation{
systemd.resource-control directives
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ bind "/unitfile" = systemd_unitfile_config[];
'includes', list(
'/unit/1',
'/unit/2',
),
),
'unit', dict(
'Assert', dict(
'PathExists', list(
'', # reset
'/path/1',
'/path/2',
),
),
),
'Condition', dict(
'PathExists', list(
'', # reset
'/path/C1',
'/path/C2',
),
),
),
'Description', 'my test',
'Requires', list('unit1', 'unit2'),
),
),
'service', dict(
'CPUAffinity', list(
list(), # reset
Expand All @@ -36,18 +36,18 @@ bind "/unitfile" = systemd_unitfile_config[];
dict(
'VAR1-1', 'val1-1 val1-1b',
'VAR1-2', 'val1-2',
),
),
dict(
'VAR2-1', 'val2-1',
'VAR2-2', 'val2-2 val2-2b',
),
),
),
'EnvironmentFile', list(
'/envfile/1',
'/envfile/2',
),
),
'TTYReset', true,
'TTYVHangup', false,
),
);
),
);

30 changes: 15 additions & 15 deletions ncm-systemd/src/main/resources/regular/tests/profiles/unitfile.pan
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ bind "/unitfile" = systemd_unitfile_config[];
'includes', list(
'/unit/1',
'/unit/2',
),
),
'unit', dict(
'Assert', dict(
'PathExists', list(
'', # reset
'/path/1',
'/path/2',
),
),
),
'Condition', dict(
'PathExists', list(
'', # reset
'/path/C1',
'/path/C2',
),
),
),
'Description', 'my test',
'Requires', list('unit1', 'unit2'),
'After', list('unit0', 'unit01'),
'Before', list('unita', 'unitb'),
),
),
'service', dict(
'CPUAffinity', list(
list(), # reset
Expand All @@ -38,16 +38,16 @@ bind "/unitfile" = systemd_unitfile_config[];
dict(
'VAR1-1', 'val1-1 val1-1b',
'VAR1-2', 'val1-2',
),
),
dict(
'VAR2-1', 'val2-1',
'VAR2-2', 'val2-2 val2-2b',
),
),
),
'EnvironmentFile', list(
'/envfile/1',
'/envfile/2',
),
),
'ExecStart', '/usr/bin/special',
'TTYReset', true,
'TTYVHangup', false,
Expand All @@ -61,14 +61,14 @@ bind "/unitfile" = systemd_unitfile_config[];
'BlockIODeviceWeight', list(list('/var', '100'), list('/tmp', '50')),
'ExecStartPre', list('/usr/bin/true', '-/bin/false'),
'ExecStopPost', '/usr/bin/true',
),
),
'socket', dict(
'ExecStartPre', list('/some/path arg1', '-/some/other/path arg2'),
'ListenStream', list('/path/to/pipe'),
'SocketUser', 'pipeuser',
'SocketGroup', 'pipegroup',
'SocketMode', '660',
),
),
'path', dict(
'PathExists', '/path/to/file',
'PathExistsGlob', '/path/to/glob*',
Expand All @@ -80,24 +80,24 @@ bind "/unitfile" = systemd_unitfile_config[];
'DirectoryMode', '0755',
'TriggerLimitIntervalSec', 10,
'TriggerLimitBurst', 5,
),
),
'mount', dict(
'What', 'server:/share',
'Where', '/data/share',
'Type', 'glusterfs',
'Options', list('_netdev', 'defaults'),
'DirectoryMode', '0750',
),
),
'timer', dict(
'OnCalendar', list('weekly', '2021-04-07 10:32:01'),
'Persistent', true,
),
),
'slice', dict(
'MemoryAccounting', true,
'MemoryLimit', 'infinity',
'MemoryMax', '28%',
),
),
'install', dict(
'WantedBy', list('1.service', '2.service'),
),
);
),
);
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ unique template service-chkconfig_simple_services;

prefix "/software/components/chkconfig/service";

"{test_on}" = dict("on","123");
"{test_add}" = dict("add",true);
"{test_on}" = dict("on", "123");
"{test_add}" = dict("add", true);

"{test_on_rename}" = dict("on","4","name","othername");
"{test_on_rename}" = dict("on", "4", "name", "othername");

# the service has to exists and/or turned on
"{test_off}" = dict("off","45");
"{test_del}" = dict("del",true,);

"{test_off}" = dict("off", "45");
"{test_del}" = dict("del", true);
6 changes: 3 additions & 3 deletions ncm-systemd/src/test/resources/service_services_ceph021.pan
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ prefix "/software/components/systemd/unit";
"state", "enabled",
"startstop", true,
"targets", list("multi-user", "graphical"),
);
);
"netconsole" = dict(
"state", "enabled",
"startstop", true,
"targets", list("multi-user"),
);
);
"rbdmap" = dict(
"state", "enabled",
"startstop", true,
"targets", list("multi-user"),
);
);
"cups" = dict(
"state", "disabled",
"startstop", false,
Expand Down
14 changes: 7 additions & 7 deletions ncm-systemd/src/test/resources/unitfile_config.pan
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ prefix "/software/components/systemd/unit";
'', # reset
'/path/1',
'/path/2',
),
),
),
'RequiresMountsFor', list("/x/y/z"),
'After', list(systemd_make_mountunit("/g/h/i/")),
),
),
'service', dict(
'CPUAffinity', list(list(), list(0,1)),
),
'CPUAffinity', list(list(), list(0, 1)),
),
);
),
);

"{replace.service}/file" = dict(
'only', true,
Expand All @@ -33,6 +33,6 @@ prefix "/software/components/systemd/unit";
'includes', list(
'/unit/1',
'/unit/2',
),
),
);
),
);

0 comments on commit a1051d5

Please sign in to comment.