<div dir="ltr"><div>Package: systemd</div><div>Version: 230-7~bpo8+2</div><div><br></div><div>When systemd is instructed to run a transient unit, it writes the unit's data</div><div>to `/run/systemd/system`. systemd v230 writes this data incorrectly. Also a</div><div>side-effect of this is that `systemctl daemon-reload` then `systemctl restart</div><div>some-service` were observed to wipe some cgroup settings of containers (very</div><div>bad).</div><div><br></div><div>$ sudo systemd-run -p MemoryLimit=1024000 -p CPUShares=1024 sleep infinity</div><div>Running as unit: run-r8a3743115ea443e798f0656bc828d246.service</div><div><br></div><div>$ cat /run/systemd/transient/run-r8a3743115ea443e798f0656bc828d246.service</div><div># This is a transient unit file, created programmatically via the systemd API. Do not edit.</div><div>[Unit]</div><div>Description=/bin/sleep infinity</div><div>[Service]</div><div>MemoryLimit=1024000[Service]</div><div>CPUShares=1024[Service]</div><div>ExecStart=</div><div>ExecStart=@/bin/sleep "/bin/sleep" "infinity"</div><div><br></div><div>Notice that the file is missing new lines. The same thing also happen if you</div><div>run a docker container for example</div><div><br></div><div>$ cat /run/systemd/transient/docker-a0cb3f641a9fc522c1ba8fca3b67ee2a82d29c1afcff3b50480713cbb4d28c05.scope</div><div># This is a transient unit file, created programmatically via the systemd API. Do not edit.</div><div>[Scope]</div><div>Slice=system.slice</div><div>[Unit]</div><div>Description=docker container a0cb3f641a9fc522c1ba8fca3b67ee2a82d29c1afcff3b50480713cbb4d28c05</div><div>[Scope]</div><div>Delegate=yes[Scope]</div><div>MemoryAccounting=yes[Scope]</div><div>CPUAccounting=yes[Scope]</div><div>BlockIOAccounting=yes[Unit]</div><div>DefaultDependencies=no</div><div>[Scope]</div><div>MemoryLimit=10737418240[Scope]</div><div>CPUShares=1024</div><div><br></div><div>On a systemd v230 host, i can use the following script to reproduce the reset</div><div>of cgroup settings:</div><div><br></div><div><br></div><div>```</div><div>#!/bin/bash</div><div><br></div><div>set -e</div><div><br></div><div>rm wtf.cid || true</div><div>docker rm -f testwtf || true</div><div>wanted=10737418240</div><div>docker run --name testwtf -d --memory $wanted --cpu-shares 1024 --cidfile wtf.cid debian:jessie sleep infinity</div><div>cid=$(cat wtf.cid)</div><div>memlimit_file="/sys/fs/cgroup/memory/system.slice/docker-$cid.scope/memory.limit_in_bytes"</div><div><br></div><div>current_limit=$(cat $memlimit_file)</div><div>echo "current limit: $current_limit, started"</div><div><br></div><div># start looping daemon-reload</div><div>num_run=$1</div><div>for i in $(seq 1 $num_run); do</div><div>        sudo systemctl daemon-reload</div><div>        sudo systemctl restart cups</div><div>        current_limit=$(cat $memlimit_file)</div><div>        echo "current limit: $current_limit, wanted $wanted"</div><div>        if [ "$current_limit" != "$wanted" ]; then</div><div>                echo "unexpected limit, dead"</div><div>                exit 1</div><div>        fi</div><div>        sleep 0.5</div><div>done</div><div>```</div><div><br></div><div>This prints out:</div><div><br></div><div>```</div><div>testwtf</div><div>a919c8fcab91966962922c44ae86711c1cada4e38f4b7124c185e8dcbf0d8077</div><div>current limit: 10737418240, started</div><div>current limit: 9223372036854771712, wanted 10737418240</div><div>unexpected limit, dead</div><div>```</div><div><br></div><div>I expect it to run successfully without resetting the cgroup limit of the</div><div>container.</div><div><br></div><div>I suggest that we bump systemd in backports to v231 or somehow backport</div><div>relevant patches.</div></div>