I am running
- arch linux 6.4.2-arch1-1 and
- openbox wm v3.6.1 with
- tint2 bar version 17.0.2 and
- systemd v253.5-2-arch
Everything is up to date.
On my tint2 bar I display time dependent information such as the weather etc.
I don't want the tint2 bar to update every few seconds because this will use too much system resources, and I may get banned from the weather site etc for too frequently polling for new data.
So I have tint2 set to update every hour, which seems reasonable.
However when I unsleep my laptop, to turn it back on, tint2 starts before I get an internet connection, so it refreshes before it is able to collect the information updates eg weather.
Can anyone suggest how after un-sleeping I might get tint2 to do a re-start immediately after detecting an internet connection.
So want to
- on any of the following: un-sleep, re-boot, switch on, un-hibernate
- after connection to internet has been detected re-start tint2 (so it will have eg fresh weather reports rather than useless old ones)
I am thinking this might involve a simple script that utilises systemd.
Here is what I have so far:
I have created a systemd service file called restart_tint2.service and placed in /etc/systemd/system/ with this in it ..
[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
Which points to this script ...
#!/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
After I suspend the laptop and re-awaken it with the power button, it kills tint2 but does not re-start it.
Not sure where I am going wrong.
Open to any means of achieving this.