Restarting Discord in Ubuntu after unsuspending

Discord does not survive suspension on Ubunu Linux (20.04, anyway). This has been the case for several Discord versions now. Searches suggests that it is stumbling on something in the NVidia drivers when the system wakes up. Here’s a solution that doesn’t stop Discord dying, but does restart it automatically it when you unsuspend.

Discord is autostarted when I log in. Unfortunately that doesn’t help in this case, because when I unsuspend I am already logged in. Unlocking the screen is not the same as logging in, so nothing triggers the autostart stuff – and in any case, everything that was autostarted should still be running, right? And probably is, so we don’t want to start everything again anyway. It’s only Discord that isn’t still running.

My first solution was a cron job that ran once every minute, checked for Discord in the process table, and started it if it wasn’t running. This worked fine, with one big caveat – no mic, and no video. When run this way, Discord doesn’t know about my microphones of webcams. In the Discord user settings in “Voice & Video” there are no devices at all to choose from. Instant messaging works fine, but to use voice or a cam I need to stop Discord completely (if “Minimise to Tray” is enabled in the Linux Settings, this means “killall discord“) and start it again.

So I moved my Discord-restarter into the autostart list. The check-and-restart bit from cron was usable as-was, I just wrapped it in a loop that runs forever, checking to see if Discord is running, starting it if it isn’t, then sleeping for 60 seconds. The only gotcha I ran into was that I had to make sure that grep did not find itself or my script when looking for “discord”. The first I solved by adding an extra check (grep -vq grep), the second I solved by making sure that “discord” was not part of the name of my script 🙂

With this in place, Discord is being started from inside my X environment, so it finds my mics and cams just fine.

Here’s the script I run as a startup application:


while true ; do
   if ! ( ps ax | grep -i discord | grep -vq grep ) ; then
      DISPLAY=:1 discord > /dev/null 2>&1
   sleep 60

This is simple and effective. Now I barely notice that Discord dies when I unsuspend my computer.

Leave a Reply

Your email address will not be published. Required fields are marked *