Skip to content
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
2 changes: 1 addition & 1 deletion ncm-systemd/src/main/pan/components/systemd/schema.pan
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ type ${project.artifactId}_unitfile_config_systemd_resource_control = {
'CPUWeight' ? ${project.artifactId}_weights
'StartupCPUWeight' ? ${project.artifactId}_weights
'StartupCPUShares' ? long(2..262144)
'CPUQuota' ? long(0..100) # percentages
'CPUQuota' ? long(0..) # percentages, > 100 means more than one CPU
'MemoryAccounting' ? boolean
'MemoryLimit' ? ${project.artifactId}_absolute_or_relative_size
'MemoryMin' ? ${project.artifactId}_absolute_or_relative_size
Expand Down
8 changes: 8 additions & 0 deletions ncm-systemd/src/main/perl/Systemd/Service/Unit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,14 @@ sub is_ufstate
return 0;
}

# slices have sort-of template units for the hierarchy (e.g. user-.slice). However, these
# units don't have proper state (as opposed to the e.g. [email protected] template units; those are static)
elsif ($unit =~ m/-\.$TYPE_SLICE$/) {
$self->info("$msg is a slice hierarchy template unit. ",
"Not going to force the state to $state and assume this is ok.");
return 1;
}

# the rest
else {
$self->debug(1, "$msg not the wanted state $state.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ bind "/unitfile" = systemd_unitfile_config[];
'BlockIODeviceWeight', list(list('/var', '100'), list('/tmp', '50')),
'ExecStartPre', list('/usr/bin/true', '-/bin/false'),
'ExecStopPost', '/usr/bin/true',
'CPUQuota', 150,
),
'socket', dict(
'ExecStartPre', list('/some/path arg1', '-/some/other/path arg2'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ contentspath=/unitfile/0
^BlockIODeviceWeight=/tmp 50$
^CPUAffinity=$
^CPUAffinity=1 2 3 4$
^CPUQuota=150%$
^Environment="VAR1-1=val1-1 val1-1b" "VAR1-2=val1-2" $
^Environment="VAR2-1=val2-1" "VAR2-2=val2-2 val2-2b" $
^EnvironmentFile=/envfile/1$
Expand Down
2 changes: 2 additions & 0 deletions ncm-systemd/src/main/resources/unitfile/section.tt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
[% END -%]
[% CASE long_infinity -%]
[%- pair.key %]=[% value == -1 ? 'infinity' : value %]
[% CASE percentages -%]
[%- pair.key %]=[% value %]%
[% CASE comma_list -%]
[%- pair.key %]=[% value.join(',') %]
[% CASE -%]
Expand Down
1 change: 1 addition & 0 deletions ncm-systemd/src/main/resources/unitfile/service-socket.tt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[%- # all Limit except NICE (schema doesn't allow NICE)
long_infinity = ['LimitAS', 'LimitCORE', 'LimitCPU', 'LimitDATA', 'LimitFSIZE', 'LimitLOCKS', 'LimitMEMLOCK', 'LimitMSGQUEUE', 'LimitNOFILE', 'LimitNPROC', 'LimitRSS', 'LimitRTPRIO', 'LimitRTTIME' 'LimitSIGPENDING', 'LimitSTACK'];
list_of_lines = ['BlockIODeviceWeight', 'BlockIOReadBandwidth', 'BlockIOWriteBandwidth', 'CPUAffinity', 'DeviceAllow', 'Environment', 'EnvironmentFile', 'ExecStart', 'ExecStartPre', 'ExecStartPost', 'ExecReload', 'ExecStop', 'ExecStopPost', 'ListenStream', 'ListenDatagram', 'ListenSequentialPacket', 'OnCalendar'];
percentages = ['CPUQuota'];
-%]
[% INCLUDE 'systemd/unitfile/section.tt' data=data -%]
6 changes: 6 additions & 0 deletions ncm-systemd/src/test/perl/service-unit.t
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,12 @@ while (my ($ufstate, $val) = each %$states) {
$out =~ s/^UnitFileState\s*=.*$/UnitFileState=enabled/m;
set_desired_output($cmdline, $out);

ok($unit->is_ufstate('user-.slice', $STATE_ENABLED), "user-.slice has ufstate $STATE_ENABLED (any state is ok for template slice");
ok($unit->is_ufstate('user-.slice', $STATE_DISABLED), "user-.slice has ufstate $STATE_DISABLED (any state is ok for template slice");

# unknown unit user-123.slice will be considered DISABLED
ok($unit->is_ufstate('user-123.slice', $STATE_DISABLED), "unkown user-123.slice has $STATE_DISABLED (any state is not ok for slice");
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");

=pod

Expand Down