may_kill_dev

This commit is contained in:
pvincent
2024-01-18 21:10:40 +04:00
parent 2eebdfac5b
commit fba1059a21
4 changed files with 29 additions and 7 deletions
+2 -2
View File
@@ -4,8 +4,8 @@
"type": "ruby_lsp",
"name": "Debug Rails",
"request": "launch",
"preLaunchTask": "PKILL: /bin/dev",
"program": "${workspaceFolder}/bin/rails server --port 3000",
"preLaunchTask": "ASK_FOR_KILL_RAILS",
"program": "${workspaceFolder}/bin/rails server --port 3000 -b 127.0.0.1",
},
]
}
+1
View File
@@ -11,4 +11,5 @@
"emmet.includeLanguages": {
"erb": "html"
},
"debug.onTaskErrors": "abort"
}
+7 -5
View File
@@ -2,13 +2,15 @@
"tasks": [
{
"type": "shell",
"label": "PKILL: /bin/dev",
"command": "kill -9 $(ss -tlnp | grep 3000 | grep -oP \"pid=\\K(\\d+)\" | head -n1)",
"detail": "Pkill previous Rails server",
"label": "ASK_FOR_KILL_RAILS",
"command": "${workspaceFolder}/bin/may_kill_dev.sh",
"detail": "ASK before killing the currently running Rails server",
"presentation": {
"showReuseMessage": false,
"reveal": "silent",
"close": true
"reveal": "always",
"close": true,
"panel": "dedicated",
"echo": false
}
}
+19
View File
@@ -0,0 +1,19 @@
#!/bin/bash
PORT=3000
pid_rails=$(ss -tlnp | grep "$PORT" | grep -oP "pid=\K(\d+)" | head -n1)
if [[ -n $pid_rails ]]; then
echo "============================================================================"
echo "Rails already runs on port $PORT, You've asked for debugger on the same port."
echo "============================================================================"
echo -n "Do you to want to kill rails process in order to launch debugger: (y/N)?: "
read -n1 answer
case $(echo $answer | tr '[A-Z]' '[a-z]') in
y|yes) kill -15 $pid_rails ;;
*) echo " means NO"; exit 1 ;;
esac
else
echo "port $PORT is free for debugger, go on..."
fi