Skip to content

Commit 9d08977

Browse files
committed
systemd: try to clean up any remaining processes in the cgroup
It might be some leftover processes that runs in the background, e.g. ssh [mux] processes.
1 parent 6338078 commit 9d08977

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lilac2/systemd.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,26 @@ def poll_rusage(
214214
subprocess.run(['systemctl', '--user', 'stop', '--quiet', name])
215215
if cgroup:
216216
# if we actually got the cgroup (i.e. service was started when we looked)
217-
wait_cgroup_disappear(cgroup)
217+
wait_cgroup_disappear(cgroup, name)
218218

219219
p = subprocess.run(['systemctl', '--user', 'is-failed', '--quiet', name])
220220
if p.returncode == 0:
221221
subprocess.run(['systemctl', '--user', 'reset-failed', '--quiet', name])
222222
return RUsage(nsec / 1_000_000_000, mem_max), timedout
223223

224-
def wait_cgroup_disappear(cgroup: str) -> None:
224+
def wait_cgroup_disappear(cgroup: str, name: str) -> None:
225225
d = f'/sys/fs/cgroup/{cgroup}'
226226
if not os.path.exists(d):
227227
return
228228

229+
count = 0
229230
while os.path.exists(d):
230231
logger.warning('waiting %s to disappear...', cgroup)
231232
time.sleep(1)
233+
count += 1
234+
if count == 10:
235+
logger.warning('killing %s.', name)
236+
subprocess.run(['systemctl', '--user', 'kill', name])
237+
elif count == 30:
238+
logger.warning('killing %s with SIGKILL.', name)
239+
subprocess.run(['systemctl', '--user', 'kill', '--signal=KILL', name])

0 commit comments

Comments
 (0)