2
0
Fork 0
rootfs/usr/local/bin/sh.zio.sys-daemon

93 lines
1.7 KiB
Plaintext
Raw Normal View History

2024-04-02 03:29:04 +02:00
#!/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"
}
2024-04-02 03:36:24 +02:00
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
}
2024-04-02 03:29:04 +02:00
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
2024-04-02 03:36:24 +02:00
#while :
#do
# check_updates()
# sleep 3600
#done
2024-04-02 03:29:04 +02:00
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