Last active
June 21, 2021 20:26
-
-
Save yondonfu/617f115dc09ed8ef8f576f0016d80d20 to your computer and use it in GitHub Desktop.
Bash script to start livepeer and monitor logs for CUDA_ERROR_ILLEGAL_ADDRESS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: ./start_and_monitor_livepeer.sh <LIVEPEER_ARGS> | |
# <LIVEPEER_ARGS> should be the flag arguments you would use with the livepeer binary | |
# Ex. `livepeer -network mainnet -orchestrator -transcoder` would instead be: | |
# `./start_and_monitor_livepeer.sh -network mainnet -orchestrator -transcoder` | |
trap cleanup EXIT | |
livepeer_args=$@ | |
start_livepeer() { | |
./livepeer $livepeer_args 2>&1 | tee livepeer.log & | |
livepeer_pid=$! | |
} | |
stop_livepeer() { | |
if [ -n "$livepeer_pid" ] && ps -p $livepeer_pid > /dev/null; then | |
kill -s TERM $livepeer_pid | |
fi | |
} | |
start_monitor() { | |
tail -fn0 livepeer.log | while read line; do | |
echo "${line}" | grep -i "CUDA_ERROR_ILLEGAL_ADDRESS" > /dev/null | |
if [ $? = 0 ]; then | |
# Restart livepeer | |
echo "CUDA_ERROR_ILLEGAL_ADDRESS detected. Restarting livepeer." | |
stop_livepeer | |
start_livepeer | |
fi | |
done | |
} | |
stop_monitor() { | |
if [ -n "$monitor_pid" ] && ps -p $monitor_pid > /dev/null; then | |
kill -s TERM $monitor_pid | |
fi | |
} | |
cleanup() { | |
stop_livepeer | |
} | |
# Start livepeer in background | |
start_livepeer | |
# Start monitor in foreground | |
start_monitor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment