Skip to content

Commit e3705d8

Browse files
authored
Merge pull request #1815 from stdweird/systemd_slice_template
ncm-systemd: template slice units will not have their state forced
2 parents 35e38fc + 3a0f3f4 commit e3705d8

File tree

7 files changed

+20
-1
lines changed

7 files changed

+20
-1
lines changed

ncm-systemd/src/main/pan/components/systemd/schema.pan

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ type ${project.artifactId}_unitfile_config_systemd_resource_control = {
253253
'CPUWeight' ? ${project.artifactId}_weights
254254
'StartupCPUWeight' ? ${project.artifactId}_weights
255255
'StartupCPUShares' ? long(2..262144)
256-
'CPUQuota' ? long(0..100) # percentages
256+
'CPUQuota' ? long(0..) # percentages, > 100 means more than one CPU
257257
'MemoryAccounting' ? boolean
258258
'MemoryLimit' ? ${project.artifactId}_absolute_or_relative_size
259259
'MemoryMin' ? ${project.artifactId}_absolute_or_relative_size

ncm-systemd/src/main/perl/Systemd/Service/Unit.pm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,14 @@ sub is_ufstate
14611461
return 0;
14621462
}
14631463

1464+
# slices have sort-of template units for the hierarchy (e.g. user-.slice). However, these
1465+
# units don't have proper state (as opposed to the e.g. [email protected] template units; those are static)
1466+
elsif ($unit =~ m/-\.$TYPE_SLICE$/) {
1467+
$self->info("$msg is a slice hierarchy template unit. ",
1468+
"Not going to force the state to $state and assume this is ok.");
1469+
return 1;
1470+
}
1471+
14641472
# the rest
14651473
else {
14661474
$self->debug(1, "$msg not the wanted state $state.");

ncm-systemd/src/main/resources/regular/tests/profiles/unitfile.pan

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ bind "/unitfile" = systemd_unitfile_config[];
6161
'BlockIODeviceWeight', list(list('/var', '100'), list('/tmp', '50')),
6262
'ExecStartPre', list('/usr/bin/true', '-/bin/false'),
6363
'ExecStopPost', '/usr/bin/true',
64+
'CPUQuota', 150,
6465
),
6566
'socket', dict(
6667
'ExecStartPre', list('/some/path arg1', '-/some/other/path arg2'),

ncm-systemd/src/main/resources/regular/tests/regexps/unitfile0/value

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ contentspath=/unitfile/0
3131
^BlockIODeviceWeight=/tmp 50$
3232
^CPUAffinity=$
3333
^CPUAffinity=1 2 3 4$
34+
^CPUQuota=150%$
3435
^Environment="VAR1-1=val1-1 val1-1b" "VAR1-2=val1-2" $
3536
^Environment="VAR2-1=val2-1" "VAR2-2=val2-2 val2-2b" $
3637
^EnvironmentFile=/envfile/1$

ncm-systemd/src/main/resources/unitfile/section.tt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
[% END -%]
1111
[% CASE long_infinity -%]
1212
[%- pair.key %]=[% value == -1 ? 'infinity' : value %]
13+
[% CASE percentages -%]
14+
[%- pair.key %]=[% value %]%
1315
[% CASE comma_list -%]
1416
[%- pair.key %]=[% value.join(',') %]
1517
[% CASE -%]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[%- # all Limit except NICE (schema doesn't allow NICE)
22
long_infinity = ['LimitAS', 'LimitCORE', 'LimitCPU', 'LimitDATA', 'LimitFSIZE', 'LimitLOCKS', 'LimitMEMLOCK', 'LimitMSGQUEUE', 'LimitNOFILE', 'LimitNPROC', 'LimitRSS', 'LimitRTPRIO', 'LimitRTTIME' 'LimitSIGPENDING', 'LimitSTACK'];
33
list_of_lines = ['BlockIODeviceWeight', 'BlockIOReadBandwidth', 'BlockIOWriteBandwidth', 'CPUAffinity', 'DeviceAllow', 'Environment', 'EnvironmentFile', 'ExecStart', 'ExecStartPre', 'ExecStartPost', 'ExecReload', 'ExecStop', 'ExecStopPost', 'ListenStream', 'ListenDatagram', 'ListenSequentialPacket', 'OnCalendar'];
4+
percentages = ['CPUQuota'];
45
-%]
56
[% INCLUDE 'systemd/unitfile/section.tt' data=data -%]

ncm-systemd/src/test/perl/service-unit.t

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,12 @@ while (my ($ufstate, $val) = each %$states) {
542542
$out =~ s/^UnitFileState\s*=.*$/UnitFileState=enabled/m;
543543
set_desired_output($cmdline, $out);
544544

545+
ok($unit->is_ufstate('user-.slice', $STATE_ENABLED), "user-.slice has ufstate $STATE_ENABLED (any state is ok for template slice");
546+
ok($unit->is_ufstate('user-.slice', $STATE_DISABLED), "user-.slice has ufstate $STATE_DISABLED (any state is ok for template slice");
547+
548+
# unknown unit user-123.slice will be considered DISABLED
549+
ok($unit->is_ufstate('user-123.slice', $STATE_DISABLED), "unkown user-123.slice has $STATE_DISABLED (any state is not ok for slice");
550+
ok(!$unit->is_ufstate('user-123.slice', $STATE_ENABLED), "user-123.slice does not have ufstate $STATE_ENABLED (any state is not ok for actual slice");
545551

546552
=pod
547553

0 commit comments

Comments
 (0)