A quick guide to stopping an ssh console -C process that wasn't shut down properly

It took me longer than I’d like to track this down, so I’m leaving a guide here for those in a similar situation (and future me).

How I got into this

I needed to updated some live staging data, so I ran prisma studio on the primary machine and proxied it to my local.

  • fly ssh console -C "npm run prisma:studio" --app [app-name]
  • Then in another terminal tab…
  • fly proxy 5556:5555 --app [app-name]
  • I updated my live data and when to shut down my ssh with ctrl+c
    • … this resulted in following message
    • Error: ssh shell: session forcibly closed; the remote process may still be running

I thought to myself: oh, okay. Whoops but I can just ssh back in ps aux for the process id (PID) and kill it. Heh, no I cannot: -bash: ps: command not found.

The Solution

  • Re-establish the proxy so you can ensure things work: fly proxy 5556:5555 --app [app-name]
  • Reconnect with ssh: fly ssh console --app [app-name]
  • (Optional) Type help and despair that you have access to kill but not to ps. Search the community and wider internet furiously for a solution that doesn’t involve needlessly attempting to install tools you don’t really want on your staging box.
  • Learn that you can find process info (including PID) by exploring /proc.
    • Find a helpful snippet that humanizes this exploration in a single line.
    • for prc in /proc/*/cmdline; { (printf "$prc "; cat -A "$prc") | sed 's/\^@/ /g;s|/proc/||;s|/cmdline||'; echo; }
      
  • Find those PIDs.
    960 npm run prisma:studio                     
    971 sh -c prisma studio 
    972 node /myapp/node_modules/.bin/prisma studio
    
  • Pick the actual node command PID (in this example 972).
  • Ask kill to do it’s thing: kill 972 (Note: don’t need to kill -9 because our process isn’t stuck just lost to us).
  • Rerun the handy one-liner to ensure the processes went away.
  • Check your proxy to make sure prisma studio stopped localhost:5556.
  • ctrl+c out of the proxy and use exit to stop your ssh

Congrats! You’re no longer running prisma studio unnecessarily!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.