Browse Source

may_kill_dev

pagy
pvincent 11 months ago
parent
commit
fba1059a21
  1. 4
      .vscode/launch.json
  2. 1
      .vscode/settings.json
  3. 12
      .vscode/tasks.json
  4. 19
      bin/may_kill_dev.sh

4
.vscode/launch.json

@ -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
.vscode/settings.json

@ -11,4 +11,5 @@
"emmet.includeLanguages": {
"erb": "html"
},
"debug.onTaskErrors": "abort"
}

12
.vscode/tasks.json

@ -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
bin/may_kill_dev.sh

@ -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
Loading…
Cancel
Save