You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is the accompanying startup.sh
There is currently an issue with the Trueblocks docker image, so that it doesn't shutdown cleanly (should be resolved soon). Additionally we are running multiple processes (chifra daemon and chifra scrape), and there are complexities with passing termination signals to the main process in a docker container. The following feels hacky but it was the only way to get all processes to shutdown before docker kills the container. It captures the shutdown signal and stalls while getting all process names that start with "chifra", and then terminating them in descending order of process id.
The issue with Trueblocks docker image results in temporary scrape files not being deleted, and on next startup chifra will interpret this as meaning an existing scraper is already underway. The delete on line 27 deals with this. In my own and Dawid's testing this hasn't caused any issues.
#!/bin/bash
set -Eeuo pipefail
# Function to stop processes
stop_processes() {
echo "Received shutdown signal"
# Get all running chifra processes
chifra_pids=$(pgrep -f chifra)
# Reverse the order of the PIDs
chifra_pids=$(echo $chifra_pids | tr " " "\n" | tac | tr "\n" " ")
# Send SIGTERM to each PID
for pid in $chifra_pids; do
echo "Sending SIGTERM to process $pid"
kill -SIGTERM $pid
# Wait for the process to terminate
wait $pid
done
}
# Do some stuff here, whatever you want.
echo "Starting Trueblocks"
# Delete the /cache/pulsechain/tmp/scrape.pid file
rm -f /cache/pulsechain/tmp/scrape.pid
# Start chifra daemon in the background
chifra daemon --url 0.0.0.0:8080 & sleep 10 && chifra scrape &
# Keep container alive until all artisan procs have stopped.
STAYALIVE="true"
IMPORTANT_PROC="chifra"
# Catch signals from docker-compose.
trap 'STAYALIVE="false"; stop_processes' TERM INT
# The same while true; sleep; loop as above, except this one uses the count of "artisan" processes and a trapped signal as its boolean val.
while [ "$STAYALIVE" = "true" ] || (pgrep -f $IMPORTANT_PROC | sed ':a;N;$!ba;s/\n/ /g'); do
# Wait for x seconds to allow processes to finish.
sleep 10
# Echo something to give some logs to docker logs.
echo "Latest version running: $STAYALIVE, Important processes running: $(pgrep -f $IMPORTANT_PROC | sed ':a;N;$!ba;s/\n/ /g' )"
done; (edited)
I edited my startup.sh script above to use: chifra daemon --url 0.0.0.0:8080 because no API requests were getting through.
from Dawid in Discord: Try changing API server listening URL to 0.0.0.0:8080: chifra daemon --url 0.0.0.0:8080. It's realted to Docker: if it have a process listening on "localhost" or 127.0.0.1, then it's blocking access from the outside
From a user in discord (dreadedhamish):
The text was updated successfully, but these errors were encountered: