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

67 lines
1.2 KiB
Bash
Executable File

#!/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 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
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