Skip to content

Instantly share code, notes, and snippets.

@junosuarez
Created December 19, 2024 05:19
Show Gist options
  • Select an option

  • Save junosuarez/be6c0b7a8b511ba3b772c8a937b6698c to your computer and use it in GitHub Desktop.

Select an option

Save junosuarez/be6c0b7a8b511ba3b772c8a937b6698c to your computer and use it in GitHub Desktop.

Revisions

  1. junosuarez created this gist Dec 19, 2024.
    6 changes: 6 additions & 0 deletions hass-svc.command
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    #!/bin/bash

    SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

    $SCRIPT_DIR/hass-svc.sh

    9 changes: 9 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@

    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

    56 changes: 56 additions & 0 deletions utm-svc.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    #! /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