#!/usr/bin/env bash _PLUG_TITLE="System Daemon" _PLUG_DESCRIPTION="" #_PLUG_ARGS=( #) _PLUG_ROOT="true" piddir="/var/run/zio" pidfile="$piddir/sh.zio.sys-daemon.pid" # TODO: Pidfiles function check_pidfile() { mkdir -p "$piddir" if [[ -f $pidfile ]]; then pid="$(cat $pidfile)" if ps -p $pid > /dev/null; then die "Already running (PID exists: $pidfile)" exit fi else touch "$pidfile" echo "$$" > "$pidfile" fi } function del_pidfile() { rm -f "$pidfile" } function check_updates() { function notify_update() { prog="$1" count="$2" /usr/local/bin/sh.zio.notify \ --level "warning" \ --message "**$(hostname -f)** completed startup at $(date "+%d-%b-%Y %H:%M:%S %Z")" \ --title "Node online" } if [[ -x "$(command -v dnf)" ]]; then dnf_updates="$(dnf check-update -q|grep -c ^[a-z0-9])" if [[ $dnf_updates > 0 ]]; then notify_update "dnf" "$dnf_updates" fi if } function notify_startup() { /usr/local/bin/sh.zio.notify \ --level "info" \ --message "**$(hostname -f)** completed startup at $(date "+%d-%b-%Y %H:%M:%S %Z")" \ --title "Node online" } function main() { check_pidfile notify_startup #while : #do # check_updates() # sleep 3600 #done sleep infinity del_pidfile } if [[ $_PLUG_INVOKED != "true" ]]; then base_dir="$(dirname "$(realpath -s "$0")")" git_dir="$base_dir/../../.." if [[ -d "$git_dir/.git" ]]; then . "$git_dir/usr/local/libexec/zio/helpers/bash.sh" else . "/usr/local/libexec/zio/helpers/bash.sh" fi export -f get_config_dir if [[ -d "$git_dir/.git" ]]; then "$git_dir/usr/local/libexec/sodalite/invoker/src/invoke.sh" "$0" $@ else "/usr/local/libexec/sodalite/invoker/src/invoke.sh" "$0" $@ fi fi