2
0
Fork 0

sh.zio.sys-daemon: add System Daemon

main
Ducky 2024-04-02 02:29:04 +01:00
parent a22c12f6e2
commit 1cc4c432b2
3 changed files with 76 additions and 0 deletions

2
.gitignore vendored
View File

@ -31,6 +31,7 @@
!/etc/systemd/system/sh.zio.backup.timer !/etc/systemd/system/sh.zio.backup.timer
!/etc/systemd/system/zio-backup.service !/etc/systemd/system/zio-backup.service
!/etc/systemd/system/zio-backup.timer !/etc/systemd/system/zio-backup.timer
!/etc/systemd/system/sh.zio.sys-daemon.service
!/etc/systemd/system/sh.zio.znc.update-cert.service !/etc/systemd/system/sh.zio.znc.update-cert.service
!/etc/systemd/system/sh.zio.znc.update-cert.timer !/etc/systemd/system/sh.zio.znc.update-cert.timer
@ -51,6 +52,7 @@
!/usr/local/bin/sh.zio.notify !/usr/local/bin/sh.zio.notify
!/usr/local/bin/sh.zio.pod-exec !/usr/local/bin/sh.zio.pod-exec
!/usr/local/bin/sh.zio.pod-systemd !/usr/local/bin/sh.zio.pod-systemd
!/usr/local/bin/sh.zio.sys-daemon
!/usr/local/bin/sh.zio.update-rootfs !/usr/local/bin/sh.zio.update-rootfs
!/usr/local/bin/sh.zio.znc.update-cert !/usr/local/bin/sh.zio.znc.update-cert
!/usr/local/bin/zio-backup !/usr/local/bin/zio-backup

View File

@ -0,0 +1,8 @@
[Unit]
Description=sh.zio.sys-daemon
[Service]
User=root
Group=root
ExecStart=/usr/local/bin/sh.zio.sys-daemon
Type=simple

View File

@ -0,0 +1,66 @@
#!/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