nul-point

完全に自分用の備忘録です。

systemctlコマンドがtimeoutになって使用できないときのTips

事象(一例)

他オプション等でもTimeoutになったときには有効

# systemctl list-unit-files
Failed to list unit files: Connection timed out

参考URL

https://gryzli.info/2016/06/18/systemd-systemctl-list-unit-files-timeouts/

Script

#!/bin/bash

find /run/systemd/system -mindepth 1 -maxdepth 1 -mtime +1 -type f -name 'run-*' \
| perl -p -e 's#^/run/systemd/system/run-(\d+).+$#$1#g' \
| sort -u \
| while read line
do
ps -o pid= -o comm= $line \
| grep -q $line \
|| rm -rf /run/systemd/system/run-$line.*
done