ノートブックがスリープモードをキャンセルし、インターネット接続を検出した後にTint2を再起動する方法は?

ノートブックがスリープモードをキャンセルし、インターネット接続を検出した後にTint2を再起動する方法は?

私は走っています

  • Arch Linux 6.4.2-arch1-1と
  • openbox wm v3.6.1が付属しています。
  • Tint2バーバージョン17.0.2および
  • システム化 v253.5-2-arch

すべてが最新の状態です。

私のTint2列には、天気などの時間関連情報が表示されます。

私はTint2列を数秒ごとに更新したくありません。これは、あまりにも多くのシステムリソースを使用し、新しいデータを頻繁にポーリングし、天候サイトなどでブロックされる可能性があるためです。

それで、Tint2を1時間ごとに更新するように設定しましたが、これは合理的なようです。

ところで、ノートブックをスリープモードにして再びオンにすると、インターネットに接続する前にTint2が起動するため、情報の更新(天気など)を収集する前に更新されます。

眠っていない直後にTint2を再起動する方法を提案できる人はいますか?後ろにインターネット接続を確認してください。

だから欲しい

  • 次のいずれかを実行します。スリープ解除、再起動、電源投入、休止状態のキャンセル
  • インターネット接続が検出されたら、Tint2を再起動します(たとえば、古い古い天気予報の代わりに新しい天気予報があります)。

私の考えでは、これは悪用に関連する可能性がありますsystemd

これが私が今まで持っているものです:

systemdというサービスファイルを作成してrestart_tint2.service入れました/etc/systemd/system/

[Unit]
Description=This service runs once only after the arch linux laptop is 1 turned on after suspend 2 re-booted 3 turned on after being switched off 4 turned on after being hibernated

After=suspend.target


[Service]
Type=oneshot
ExecStart=/home/$USER/Dropbox/linux_config/script_tint2_restart_after_sleep/restart_tint2.sh


[Install]
WantedBy=suspend.target

このスクリプトを指すのは...

#!/bin/bash

# function to check internet connectivity
check_internet() {
  ping -c 1 8.8.8.8 >/dev/null 2>&1
}

# function to restart tint2
restart_tint2() {
  if pgrep -x "tint2" >/dev/null; then
    pkill -x "tint2"
  fi

  sleep 1

  tint2 & disown
}

# check internet connectivity
check_internet

# if internet is not available, wait and check again
while [ $? -ne 0 ]; do
  sleep 5
  check_internet
done

# restart tint2 after internet connection is detected
restart_tint2


exit 0

ノートブックを一時停止し、電源ボタンを使用して再起動すると、Tint2は終了しますが、再起動しません。

私がどこで間違っているのかわかりません。

この目標を達成するには、あらゆる方法で開かれている必要があります。

ベストアンサー1

systemd serviceというテキストファイルを生成してこのコンテンツrestart_tint2.serviceに入れます。/etc/systemd/system/

[Unit]
Description=This service runs once only after the arch linux laptop is 1 turned on after suspend 2 re-booted 3 turned on after being switched off 4 turned on after being hibernated

After=suspend.target hibernate.target


[Service]
Type=oneshot  
# point to the location of the script given below
ExecStart=/home/$USER/Dropbox/linux_config/script_tint2_restart_after_sleep/restart_tint2.sh


[Install]
WantedBy=suspend.target

restart_tint2.sh条件が満たされると、上記のサービスファイルは次のスクリプト(これを行う)を呼び出します。

#!/bin/bash



# function to check internet connectivity

check_internet() {
  ping -c 1 8.8.8.8 >/dev/null 2>&1
}



# function to restart tint2

restart_tint2() {

# the below is the only solution that works, 
#  both killing, then re-starting tint2

killall -SIGUSR1 tint2


}

# check for internet connectivity

check_internet

# if internet is not available, wait and check again
while [ $? -ne 0 ]; do
  sleep 5
  check_internet
done

# restart tint2 after internet connection is detected
restart_tint2


exit 0

それだけで、作業ソリューション

おすすめ記事