システムサービスのデバッグ

システムサービスのデバッグ

システムのCPU温度を監視してクロック速度が高すぎると、それを調整するデーモンを作成しようとしていますが、以前にデーモンを作成したことがないので、正しくしているかどうかはわかりません。

/usr/local/lib以下に基づいて、内部フォルダに2つのファイルを作成しました。ファイル階層、とthrottle_daemon呼ばれ、そしてに連絡しました。throttle_daemonthrottle_daemon.servicethrottle_daemon.service/etc/systemd/system/throttle_daemon.service

これはthrottle_daemon

# !/bin/bash

export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
export DISPLAY=:1

CPU_TEMP=$(sensors -f | grep -Po "Tdie:\s*\+\d+" | grep -Po "\d+")

# su - aaron -c "/usr/bin/notify-send 'CPU Throttle Daemon' 'CPU Temp is $CPU_TEMP'"

if [ $CPU_TEMP -ge 140 ]; then
    su - aaron -c "notify-send 'CPU Throttle Daemon' 'Throttling CPU'"
    touch /var/tmp/throttle.flag
    for cpu in /sys/devices/system/cpu/cpu*/; do
        cpu=${cpu%*/}  # Remove the trailing "/"
        echo "3200000" | sudo tee "$cpu/cpufreq/scaling_max_freq"
    done
elif [ $CPU_TEMP -le 113 ]; then
    if [ -f /var/tmp/throttle.flag ]; then
        su - aaron -c "notify-send 'CPU Throttle Daemon' 'Un-Throttling CPU'"
        for cpu in /sys/devices/system/cpu/cpu*/; do
            cpu=${cpu%*/}  # Remove the trailing "/"
            echo "3600000" | sudo tee "$cpu/cpufreq/scaling_max_freq"
        done
        rm /var/tmp/throttle.flag
    fi
fi

そして私throttle_daemon.service

[Unit]
Description="CPU Throttle Service"

[Service]
Type=simple
BusName=unix:path=/run/usr/1000/bus
NotifyAccess=all
Restart=always
RestartSec=1s
Environment=DBUS_SESSION_BUS_ADDRESS=unix:abstract=/run/user/1000/bus
ExecStart=/usr/local/lib/throttle_daemon/throttle_daemon

[Install]
WantedBy=multi-user.target

コマンドラインからスクリプトを実行するとwatch -n 1 sudo ./throttle_daemon期待どおりに機能しますが、サービスを設定すると機能しません。私がsudo systemctl start throttle_daemon.serviceそれを取得するとエラーは発生しませんが、何もしません。

notify-send毎秒毎に私のCPUの現在の温度をpingしたかったのに、なぜダメなのでしょうか?

ベストアンサー1

私が経験している問題は、/bin/bash私の回線ExecStart=で何かが欠けていたということでした。

そのため、次のように変更する必要があります。

ExecStart=/usr/local/lib/throttle_daemon/throttle_daemon

到着

ExecStart=/bin/bash /usr/local/lib/throttle_daemon/throttle_daemon

また、タイムアウト設定がありません。以下を追加する必要があります。

StartLimitBurst=0

私の[Service]立場では、その後私のプログラムは期待どおりに実行されます。

私もデスクトップを実行しているのでnotWantedByに変更しましたが、xサーバーなしで端末で実行すると通知がクラッシュするようですが、これを確認することはできません。graphical.targetmulti.user.target

おすすめ記事