2024-01-03 07:31:42 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
start_process() {
|
2024-01-03 08:51:15 +00:00
|
|
|
GOEXPERIMENT=arenas go run ./... &
|
2024-02-19 06:28:44 +00:00
|
|
|
local process_pid=$!
|
|
|
|
local child_process_pid=$(pgrep -P $process_pid)
|
|
|
|
echo "Process started with PID $process_pid and child PID $child_process_pid"
|
2024-01-03 07:31:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
is_process_running() {
|
2024-02-19 06:28:44 +00:00
|
|
|
local process_pid=$(ps -ef | grep "exe/node" | grep -v grep | awk '{print $2}')
|
2024-01-03 07:31:42 +00:00
|
|
|
ps -p $process_pid > /dev/null 2>&1
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
kill_process() {
|
2024-02-19 06:28:44 +00:00
|
|
|
local process_count=$(ps -ef | grep "exe/node" | grep -v grep | wc -l)
|
|
|
|
local process_pids=$(ps -ef | grep "exe/node" | grep -v grep | awk '{print $2}' | xargs)
|
|
|
|
|
|
|
|
if [ $process_count -gt 0 ]; then
|
|
|
|
echo "killing processes $process_pids"
|
|
|
|
kill $process_pids
|
|
|
|
|
|
|
|
local child_process_count=$(pgrep -P $process_pids | wc -l)
|
|
|
|
local child_process_pids=$(pgrep -P $process_pids | xargs)
|
|
|
|
if [ $child_process_count -gt 0 ]; then
|
|
|
|
echo "killing child processes $child_process_pids"
|
|
|
|
kill $child_process_pids
|
|
|
|
else
|
|
|
|
echo "no child processes running"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "no processes running"
|
|
|
|
fi
|
2024-01-03 07:31:42 +00:00
|
|
|
}
|
|
|
|
|
2024-02-19 06:28:44 +00:00
|
|
|
kill_process
|
|
|
|
|
2024-01-03 07:31:42 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
sleep 60
|
|
|
|
done
|