9

I was connected to my aws debian wheezy server and while running apt-get upgrade the ssh pipe broke. I didn't use screen or anything, so I don't think there's a way to recover that session.

If I reconnect with a new ssh session and run ps aux | grep apt, I can see that apt and dpkg are still running

They've been running for hours actually. I can't imagine that it would be safe to kill those processes as they might be modifying system libs/binaries, but what can I do? What if they are waiting for keyboard input or the like? I had said y when apt originally asked me to install the updates, but I don't know if it needed further user input. I plan on waiting a few more hours for dpkg and apt to hopefully complete what they're doing.. but if nothing happens, what are my options?

HalosGhost
  • 4,790
Felix Mc
  • 303
  • 4
  • 7

4 Answers4

3

You can't regain the session. And so you cannot do anything to interact with that process.

I don't think the process is running. I guess the apt-get might have become a zombie by now. Anyway you can check the process using ps or top. If it's running, then let go and monitor it to finish. If it stays idle just kill it.

And then you can simply run apt-get upgrade once again after killing the process, to finish or repair any package being upgraded while the session crashed.

beginer
  • 2,708
  • On my Pi 5, the subsequent apt-get upgrade gave me the error E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem. Just run that if you see the error. Personally, I'm running sudo apt-get upgrade again after dpkg to be safe. – allidoiswin Mar 17 '24 at 19:32
2

I think it is ok to send them a SIGINT (keyboard interruption, i.e. Ctrl+C) signal:

killall -SIGINT apt-get

or

killall -2 apt-get

You may also try to do it twice or more

2

You can try to reattach the session with a tool like reptyr, but that doesn't always work.

You can kill apt, dpkg and their subprocesses at any time. All package maintenance tasks are supposed to resist a sudden power failure. Run the command again to complete it.

Make sure to send a SIGINT or SIGTERM signal to APT and dpkg, not a SIGKILL. A SIGKILL would leave lock files in place. This is a general principle: don't use SIGKILL when SIGINT would do.

  • All package maintenance tasks are supposed to resist a sudden power failure

    I don't know about latest debian versions, but with debian 4-5 I had got into a trouble supposing this

    – sshilovsky Sep 22 '14 at 08:32
0

This helped me to do better in the future: use 'screens'

This Debian post helped me to fix my acute problem:

https://wiki.debian.org/Teams/Dpkg/FAQ

sudo fuser -vki -TERM /var/lib/dpkg/lock /var/lib/dpkg/lock-frontend

sudo dpkg --configure --pending