From e94c3f6ee972a4e82d02835934a2d803ca4bc3c1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Fri, 28 Feb 2025 10:19:20 +0100
Subject: [PATCH] remote byebug to keep foreman clean

---
 bin/debug                     | 21 +++++++++++++++++++++
 config/initializers/byebug.rb |  8 ++++++++
 2 files changed, 29 insertions(+)
 create mode 100755 bin/debug
 create mode 100644 config/initializers/byebug.rb

diff --git a/bin/debug b/bin/debug
new file mode 100755
index 000000000..af4bcd068
--- /dev/null
+++ b/bin/debug
@@ -0,0 +1,21 @@
+#!/usr/bin/env sh
+
+port=8989
+
+while getopts ":p:" opt; do
+  case ${opt} in
+    p)
+      port=$OPTARG
+      ;;
+    :)
+      echo "Option -${OPTARG} requires an argument."
+      exit 1
+      ;;
+    \?)
+      echo "Invalid option: -${OPTARG}"
+      exit 1
+      ;;
+  esac
+done
+
+exec bundle exec byebug -R localhost:$port
\ No newline at end of file
diff --git a/config/initializers/byebug.rb b/config/initializers/byebug.rb
new file mode 100644
index 000000000..cd3daefb6
--- /dev/null
+++ b/config/initializers/byebug.rb
@@ -0,0 +1,8 @@
+if Rails.env.development?
+  require 'byebug/core'
+  begin
+    Byebug.start_server 'localhost', ENV.fetch('BYEBUG_SERVER_PORT', 8989).to_i
+  rescue Errno::EADDRINUSE
+    Rails.logger.debug 'Byebug server already running'
+  end
+end
-- 
GitLab