Skip to content

Instantly share code, notes, and snippets.

@junosuarez
Created December 19, 2024 05:19
Show Gist options
  • Save junosuarez/be6c0b7a8b511ba3b772c8a937b6698c to your computer and use it in GitHub Desktop.
Save junosuarez/be6c0b7a8b511ba3b772c8a937b6698c to your computer and use it in GitHub Desktop.

this is an operator to keep the hass UTM VM started

hass-svc.sh - the script which implements healthchecking and restarting svc.log - status log hass-svc.command - wrapper to start hass-svc at login, set in System Settings > Login Items > Open at Login

note, this all is convoluted and an imperfect solution, but good enough for now

#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
$SCRIPT_DIR/hass-svc.sh
#! /bin/bash
VM_NAME=hass
INTERVAL_SEC=15
function getStatus() {
utmctl status "$VM_NAME"
}
function isoDate() {
date -u +"%Y-%m-%dT%H:%M:%SZ"
}
function log() {
echo "$(isoDate) - $@" | tee -a ~/hass/svc.log
}
function tryStart() {
log fix:try_start
utmctl start "$VM_NAME"
sleep 1
}
function tick() {
case "$(getStatus)" in
"started")
log check:ok
;;
"stopped")
log check:e_stopped
#log dbg:lets do something
tryStart
tick
;;
"paused")
log check:e_paused
tryStart
tick
;;
*)
log check:e_unknown
;;
esac
}
function main() {
log service_monitor_started
while true; do
tick
sleep $INTERVAL_SEC
done
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment