Merge remote-tracking branch 'origin/karen-v2' into beta

This commit is contained in:
AaronDewes 2022-05-22 13:07:12 +00:00
commit 9a6501a80e
3 changed files with 25 additions and 84 deletions

View File

@ -108,7 +108,7 @@ services:
ipv4_address: $DASHBOARD_IP ipv4_address: $DASHBOARD_IP
manager: manager:
container_name: manager container_name: manager
image: ghcr.io/runcitadel/manager:v0.0.12@sha256:de97eeb6e8caae5d1a8aeb045213621cf8e6e928177236bb0b3c25e76f6cd041 image: ghcr.io/runcitadel/manager:feat-karen-v2@sha256:61dfc6a23bb6603096673e517ec058730ca7e1fbe251df38760c2860d03b1dd0
depends_on: depends_on:
- tor - tor
- redis - redis
@ -121,6 +121,7 @@ services:
- ${PWD}/info.json:/info.json - ${PWD}/info.json:/info.json
- ${PWD}/db:/db - ${PWD}/db:/db
- ${PWD}/events/signals:/signals - ${PWD}/events/signals:/signals
- ${PWD}/events:/events
- ${PWD}/apps:/apps - ${PWD}/apps:/apps
- ${PWD}/lnd:/lnd:ro - ${PWD}/lnd:/lnd:ro
- ${PWD}/statuses:/statuses - ${PWD}/statuses:/statuses

View File

@ -6,8 +6,4 @@
CITADEL_ROOT="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../..)" CITADEL_ROOT="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../..)"
signal="${1}" "${CITADEL_ROOT}/scripts/app" "$@"
command=${signal%%"-"*}
app=${signal#*"-"}
"${CITADEL_ROOT}/scripts/app" "${command}" "${app}"

100
karen
View File

@ -1,83 +1,27 @@
#!/usr/bin/env bash #!/usr/bin/env python3
# SPDX-FileCopyrightText: 2020 Umbrel. https://getumbrel.com import socket
# SPDX-FileCopyrightText: 2021-2022 Citadel and contributors. import os
#
# SPDX-License-Identifier: GPL-3.0-or-later
# karen watches for signals and executes triggers in the events dir rootDir = os.path.dirname(os.path.abspath(__file__))
# karen gets triggered a lot os.chdir(rootDir)
check_root () { if os.path.exists("events/karen"):
if [[ $UID != 0 ]]; then os.remove("events/karen")
echo "Error: This script must be run as root."
echo "Can I speak to a manager please?"
exit 1
fi
}
check_if_not_already_running() { server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
if ps ax | grep $0 | grep -v $$ | grep bash | grep -v grep server.bind("events/karen")
then
echo "karen is already running"
exit 1
fi
}
check_dependencies () { while True:
for cmd in "$@"; do server.listen(1)
if ! command -v $cmd >/dev/null 2>&1; then conn, addr = server.accept()
echo "This script requires \"${cmd}\" to be installed" datagram = conn.recv(1024)
exit 1 if datagram:
fi instructions = datagram.decode("utf-8").strip().split()
done cmd = instructions[0]
} if(cmd == "trigger"):
trigger = instructions[1]
check_root instructions.pop(0)
instructions.pop(0)
check_if_not_already_running os.system("events/triggers/{} {}".format(trigger, " ".join(instructions)))
conn.close()
check_dependencies fswatch readlink dirname
if [[ -n "$1" ]]; then
root_dir="$(readlink -f $1)"
else
root_dir="$(dirname $(readlink -f ${BASH_SOURCE[0]}))/events"
fi
signal_dir="$root_dir/signals"
trigger_dir="$root_dir/triggers"
if [[ ! -d "$root_dir" ]]; then
echo "Root dir does not exist '$root_dir'"
exit 1
fi
echo "karen will start in 30 seconds"
sleep 30
echo "karen is running in $root_dir"
fswatch -0 --event=PlatformSpecific $signal_dir | while read -d "" event; do
signal="${event#"$signal_dir"}"
signal="${signal#"/"}"
trigger="$trigger_dir/$signal"
args=""
# If signal isn't an empty string, then it's a signal
if [[ -n "$signal" ]]; then
echo "Got signal: $signal"
# If the signal starts wih app-, the trigger is "$trigger_dir/app"
# and the args are the rest of the signal
if [[ "$signal" =~ ^app- ]] && [[ "$signal" != "app-update" ]]; then
trigger="$trigger_dir/app"
args="${signal#"app-"}"
fi
if test -x "$trigger"; then
echo "karen is getting triggered!"
if [[ ! -f "statuses/update-in-progress" ]]; then
"$trigger" $args &
fi
else
echo "No trigger found"
fi
fi
done