ceremonyclient/node/release_autorun.sh

74 lines
2.0 KiB
Bash
Raw Normal View History

2024-05-25 04:53:57 +00:00
#!/bin/bash
start_process() {
version=$(cat config/version.go | grep -A 1 "func GetVersion() \[\]byte {" | grep -Eo '0x[0-9a-fA-F]+' | xargs printf "%d.%d.%d")
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if ! which cpulimit; then
echo "cpulimit not installed, please install it before running the node"
exit 1
fi
2024-05-29 17:48:33 +00:00
if [[ $(uname -m) == "aarch64"* ]]; then
2024-05-25 04:53:57 +00:00
./node-$version-linux-arm64 &
2024-05-25 05:11:06 +00:00
main_process_id=$!
sleep 20
ps -eo pid,args | grep "node-$version-linux-arm64 --core" | grep -v grep | gawk '{print $1}' | xargs -L 1 cpulimit -l 50 -z -b -p
2024-05-25 04:53:57 +00:00
else
./node-$version-linux-amd64 &
2024-05-25 05:11:06 +00:00
main_process_id=$!
sleep 20
ps -eo pid,args | grep "node-$version-linux-amd64 --core" | grep -v grep | gawk '{print $1}' | xargs -L 1 cpulimit -l 50 -z -b -p
2024-05-25 04:53:57 +00:00
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
./node-$version-darwin-arm64 &
2024-05-25 05:11:06 +00:00
main_process_id=$!
2024-05-25 04:53:57 +00:00
else
echo "unsupported OS for releases, please build from source"
exit 1
fi
2024-05-25 05:11:06 +00:00
echo "process started with PID $main_process_id"
2024-05-25 04:53:57 +00:00
}
is_process_running() {
ps -p $main_process_id > /dev/null 2>&1
return $?
}
kill_process() {
2024-05-25 05:11:06 +00:00
local process_count=$(ps -ef | grep "node-$version" | grep -v grep | wc -l)
local process_pids=$(ps -ef | grep "node-$version" | grep -v grep | awk '{print $2}' | xargs)
2024-05-25 04:53:57 +00:00
if [ $process_count -gt 0 ]; then
echo "killing processes $process_pids"
kill $process_pids
else
echo "no processes running"
fi
}
kill_process
start_process
while true; do
if ! is_process_running; then
echo "process crashed or stopped. restarting..."
start_process
fi
git fetch
local_head=$(git rev-parse HEAD)
remote_head=$(git rev-parse @{u})
if [ "$local_head" != "$remote_head" ]; then
kill_process
git pull
start_process
fi
2024-05-29 22:33:23 +00:00
sleep 43200
2024-05-25 04:53:57 +00:00
done