Skip to content

Commit 0d25f25

Browse files
justin808claude
andcommitted
improve: expand stale file cleanup to include Rails server.pid
Enhanced the cleanup functionality to handle both Overmind socket files and Rails server.pid files. The cleanup safely removes stale pid files only when the associated processes are no longer running. This addresses both Overmind socket issues and potential Rails server conflicts from stale pid files. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 2d5154a commit 0d25f25

File tree

1 file changed

+35
-9
lines changed
  • lib/generators/react_on_rails/bin

1 file changed

+35
-9
lines changed

lib/generators/react_on_rails/bin/dev

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def ensure_procfile(procfile)
2929
exit 1
3030
end
3131

32-
def cleanup_stale_sockets
32+
def cleanup_stale_files
33+
cleaned_any = false
34+
3335
# Check for stale overmind socket files
3436
socket_files = [".overmind.sock", "tmp/sockets/overmind.sock"]
3537

@@ -41,14 +43,33 @@ def cleanup_stale_sockets
4143
if File.exist?(socket_file)
4244
puts " 🧹 Cleaning up stale socket: #{socket_file}"
4345
File.delete(socket_file) rescue nil
46+
cleaned_any = true
4447
end
4548
end
4649
end
50+
51+
# Check for stale Rails server.pid file
52+
server_pid_file = "tmp/pids/server.pid"
53+
if File.exist?(server_pid_file)
54+
pid = File.read(server_pid_file).to_i
55+
# Check if process is actually running
56+
begin
57+
Process.kill(0, pid)
58+
# Process exists, don't clean up
59+
rescue Errno::ESRCH
60+
# Process doesn't exist, clean up stale pid file
61+
puts " 🧹 Cleaning up stale Rails pid file: #{server_pid_file}"
62+
File.delete(server_pid_file) rescue nil
63+
cleaned_any = true
64+
end
65+
end
66+
67+
cleaned_any
4768
end
4869

4970
def run_with_process_manager(procfile)
50-
# Clean up stale sockets before starting
51-
cleanup_stale_sockets
71+
# Clean up stale files before starting
72+
cleanup_stale_files
5273

5374
if installed?("overmind")
5475
system "overmind start -f #{procfile}"
@@ -159,12 +180,17 @@ def kill_processes
159180
end
160181
end
161182

162-
# Clean up socket files
163-
socket_files = [".overmind.sock", "tmp/sockets/overmind.sock"]
164-
socket_files.each do |socket_file|
165-
if File.exist?(socket_file)
166-
puts " 🧹 Removing #{socket_file}"
167-
File.delete(socket_file) rescue nil
183+
# Clean up socket and pid files
184+
cleanup_files = [
185+
".overmind.sock",
186+
"tmp/sockets/overmind.sock",
187+
"tmp/pids/server.pid"
188+
]
189+
190+
cleanup_files.each do |file|
191+
if File.exist?(file)
192+
puts " 🧹 Removing #{file}"
193+
File.delete(file) rescue nil
168194
killed_any = true
169195
end
170196
end

0 commit comments

Comments
 (0)