#!/bin/bash RAILS_ENV=production bundle exec rake assets:precompile # Get the current directory name current_dir=$(basename "$(pwd)") # Get the list of process IDs matching the criteria process_ids=$(ps -e -o pid,cmd | grep -E "puma|sidekiq" | grep "[ /]${current_dir}[ /]" | awk '{print $1}') cmds=$(ps -e -o pid,cmd | grep -E "puma|sidekiq" | grep "[ /]${current_dir}[ /]" | awk '{print $0}') # Check if any processes match the criteria if [ -n "$process_ids" ]; then echo "Restarting $current_dir" echo "$cmds" # echo "Processes to be killed:" # echo "$process_ids" # Send SIGTERM signal to each matching process for pid in $process_ids; do echo "Killing process $pid" kill -TERM "$pid" done else echo "No matching processes found." fi