#the queue job gets shut down for 2 days of inactivity??

11 messages · Page 1 of 1 (latest)

rugged marsh
#

so i'm putting my website in a server (50gb with good ram amd 5059x) and when i run this command nohup php artisan queue:work i check it with top command and i see it there, but then after let's say two days or three i don't find the pid of the queue; like i guess when the server is hibernating for inactivity;

how to solve this issue, is there a way besides cron jobs, or is cron jobs the right solution

eager birch
rugged marsh
#

so no thing like this

#!/bin/bash

# Configuration
PID_FILE="laravel_queue_pid"
LOG_FILE="queue_monitor.log"
ARTISAN_PATH="artisan" # Change this if needed (e.g., "MainWebsite/artisan")

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

# Create log file if it doesn't exist
if [ ! -f "$LOG_FILE" ]; then
    touch "$LOG_FILE"
    log_message "Log file created"
fi

log_message "Queue monitor started"

# Check if PID file exists
if [ -f "$PID_FILE" ]; then
    PID=$(cat "$PID_FILE")
    log_message "Found PID file with PID: $PID"
    
    # Check if process is running
    if ps -p "$PID" > /dev/null; then
        log_message "Process with PID $PID is running. Queue worker is active."
        exit 0
    else
        log_message "Process with PID $PID is not running. Will start new queue worker."
    fi
else
    log_message "PID file not found. Will start queue worker."
fi

# Start the queue worker with nohup
log_message "Starting new queue worker..."
QUEUE_OUTPUT=$(nohup php $ARTISAN_PATH queue:work > /dev/null 2>&1 & echo $!)

# Extract PID from the output
NEW_PID=$QUEUE_OUTPUT
log_message "Started new queue worker with PID: $NEW_PID"

# Save the PID to the file (using > to overwrite)
echo $NEW_PID > "$PID_FILE"
log_message "Saved PID to $PID_FILE"

log_message "Queue monitor completed"

tough prairie
#

This is just a shell that triggers the nohup again

rugged marsh
#

cuz i'm in shared hosting so nothing much about installing stuff

tough prairie
white stirrup
#

There's a pretty big chance that the shared hosting platform doesn't let you run long-running processes

pulsar patio
#

Probably the "best" solution here would be PM2.
But yeah, generally shared hosts don't allow any of these modifications, as you don't have sudo permissions, so there's no way to add/alter the supervisor config. So it would only be possible if they provide that functionality through the UI or something. I'd honestly recommend to look for solutions that offer more freedom, such as a VPS. That way you have full control over the server and you can set up things properly, instead of dealing with workarounds

empty latch
rugged marsh
#

i see