Last active
March 17, 2021 06:43
-
-
Save raek/a547464bc67aef9928da8c7fc16ac5d2 to your computer and use it in GitHub Desktop.
Läs elmätaren
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# INSTALLING (Running the meter poller as a user service) | |
# Put the script in ~/.local/bin/run_in_loop.sh (and make it executable) and the service description in ~.config/systemd/user/meter-poller.service . | |
# Allow your user to run service while not logged in (only needed once this computer) | |
sudo loginctl enable-linger $USER | |
# Tell systemd to start meter-poller.service at boot (done by installing symlinks) | |
systemctl --user enable meter-poller.service | |
# Tell systemd to also start the meter-poller.service now | |
systemctl --user start meter-poller.service | |
# Check the status of the service (is it running? proces tree, stdout log, etc) | |
systemctl --user status meter-poller.service | |
# Check the log for the service | |
journalctl --user-unit meter-poller.service -e | |
# Replace -e with -f to "follow" the output of the service live | |
# See all the user services running (cool colors! trees!) | |
systemctl --user status | |
# Reload the service config | |
systemctl --user daemon-reload | |
# Restart the service | |
systemctl --user restart meter-poller.service | |
# UNINSTALLING | |
# Stop service | |
systemctl --user stop meter-poller.service | |
# Disable automatic start | |
systemctl --user disable meter-poller.service | |
# You can now remove the files |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Electricity Meter Polling Service | |
[Service] | |
ExecStart=%h/.local/bin/run_in_loop.sh 10 poll_meter.sh | |
Restart=always | |
[Install] | |
WantedBy=default.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if (( $# < 2 )); then | |
echo "Usage: run_in_loop.sh <seconds> <command> <arg1> <arg2> ..." | |
exit 1 | |
fi | |
interval=$1 | |
shift | |
while true; do | |
"$@" | |
sleep $interval | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment