Skip to content

Commit

Permalink
Update uglyfeed.sh
Browse files Browse the repository at this point in the history
works on fresh linux (Ubuntu 22) installs 

```
apt update && apt -y upgrade
apt install -y git python3-pip python-is-python3

git clone https://github.com/fabriziosalmi/UglyFeed.git
cd UglyFeed/

pip install -r requirements.txt
chmod +x uglyfeed.sh
./uglyfeed.sh
```
  • Loading branch information
fabriziosalmi authored May 30, 2024
1 parent 43ae218 commit 55dd8af
Showing 1 changed file with 45 additions and 9 deletions.
54 changes: 45 additions & 9 deletions uglyfeed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,67 @@
# Script configuration (easily maintainable)
scripts=(
"main.py"
"llm_processor.py" # this will not work anymore, a proper solution is coming, in the meanwhile.. check examples below
"llm_processor.py"
"json2rss.py"
"serve.py"
)
logfile="uglyfeed.log"
port=8000 # Adjust to the port that serve.py uses

# Function to log messages with timestamps
log_message() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1" >> "$logfile"
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1" | tee -a "$logfile"
}

# Function to check if a port is in use
is_port_in_use() {
lsof -i:$1 > /dev/null
return $?
}

# Function to kill process using a specific port
kill_process_on_port() {
fuser -k $1/tcp
}

# Create or truncate the log file at the start of execution
: > "$logfile"

# Start execution
log_message "Script execution started"

for script in "${scripts[@]}"; do
log_message "Running $script..."

# Run script and redirect output/errors to log
python "$script" > >(tee -a "$logfile") 2>&1
exit_code=$?

if [ $exit_code -eq 0 ]; then
log_message "$script completed successfully"
if [ "$script" == "serve.py" ]; then
# Check if the port is already in use
if is_port_in_use $port; then
log_message "Port $port is in use. Attempting to kill the existing process."
kill_process_on_port $port
sleep 2 # Wait a bit to ensure the process is terminated
fi

# Run serve.py in the background and capture its output
python "$script" > >(tee -a "$logfile") 2>&1 &
pid=$!
log_message "$script started as background process with PID $pid"
log_message "Waiting for $script to initialize..."
sleep 5 # Adjust sleep time if needed to ensure serve.py has enough time to start
if ps -p $pid > /dev/null; then
log_message "$script is running"
else
log_message "ERROR: $script failed to start"
fi
else
log_message "ERROR: $script failed with exit code $exit_code"
# Run other scripts and redirect output/errors to log
python "$script" > >(tee -a "$logfile") 2>&1
exit_code=$?

if [ $exit_code -eq 0 ]; then
log_message "$script completed successfully"
else
log_message "ERROR: $script failed with exit code $exit_code"
fi
fi
done

Expand Down

0 comments on commit 55dd8af

Please sign in to comment.