82 lines
2.2 KiB
Bash
Executable File
82 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
start_time=$(date +%s)
|
|
|
|
# Set environment variables
|
|
export GLITCHTIP_DSN="https://d272afa8b4bd4308b3cf99ee74e1dc97@glitch.nixc.us/2"
|
|
export LOG_FILES="test_log_1.log,test_log_2.log"
|
|
|
|
echo "Using Glitchtip DSN: $GLITCHTIP_DSN"
|
|
echo "Monitoring log files: $LOG_FILES"
|
|
|
|
# Create test log files
|
|
echo "Creating test log files..."
|
|
echo "Initial log content" > test_log_1.log
|
|
echo "Initial log content" > test_log_2.log
|
|
|
|
# Determine the OS and architecture
|
|
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
|
ARCH="$(uname -m)"
|
|
|
|
case $ARCH in
|
|
x86_64) ARCH="amd64" ;;
|
|
arm64 | aarch64) ARCH="arm64" ;;
|
|
arm*) ARCH="arm/v7" ;;
|
|
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
|
|
esac
|
|
|
|
BINARY="./dist/inotify-glitch_${OS}_${ARCH}"
|
|
|
|
# Check if the binary exists
|
|
if [ ! -f "$BINARY" ]; then
|
|
echo "Binary for ${OS}_${ARCH} not found. Please ensure the correct binary is present."
|
|
exit 1
|
|
fi
|
|
|
|
# Run the Go program in the background
|
|
echo "Starting the Go program: $BINARY"
|
|
$BINARY &
|
|
|
|
# Capture the PID of the Go program
|
|
GO_PID=$!
|
|
|
|
# Give the program a moment to start
|
|
sleep 2
|
|
|
|
# Append a different error line to each log file
|
|
echo "Appending error line to test_log_1.log..."
|
|
echo "Error in log 1: Test error message 1" >> test_log_1.log
|
|
|
|
echo "Appending error line to test_log_2.log..."
|
|
echo "Error in log 2: Test error message 2" >> test_log_2.log
|
|
|
|
# Give the program some time to process the changes
|
|
sleep 5
|
|
|
|
# Check if the Go program detected the changes (you can enhance this section with more specific checks)
|
|
echo "Check the logs to verify the program detected the error lines."
|
|
|
|
# Capture Go program logs for debugging
|
|
ps -p $GO_PID > /dev/null
|
|
if [ $? -eq 0 ]; then
|
|
echo "The Go program is running."
|
|
else
|
|
echo "The Go program has terminated unexpectedly."
|
|
fi
|
|
|
|
# Cleanup: kill the Go program
|
|
echo "Terminating the Go program..."
|
|
kill $GO_PID
|
|
|
|
# Optionally: Remove test log files
|
|
echo "Removing test log files..."
|
|
rm test_log_1.log test_log_2.log
|
|
|
|
end_time=$(date +%s)
|
|
execution_time=$((end_time - start_time))
|
|
|
|
# Fix for macOS date command
|
|
execution_time_formatted=$(printf '%02d:%02d:%02d' $((execution_time/3600)) $((execution_time%3600/60)) $((execution_time%60)))
|
|
|
|
echo "Execution time: $execution_time_formatted"
|