While waiting on dinner at the restaurant tonight, I noticed on my phone’s mail app (K-9 Mail) that my emails weren’t being filtered like they should. Automated notifications that normally would be Marked as Read by one of the many rules I have in Thunderbird were going unmodified.
That’s when I remembered that, an hour before, I closed Thunderbird on my Ubuntu desktop to free up some memory before launching it again. What I failed to do was launch it again.
So here I am with my usual ever-present safety net no longer present. How to fix this?
Well, duh, the answer isn’t simple until I see the answer. Then it’s a forehead-smacking “DUH” moment.
On my phone, I open JuiceSSH and click the SSH profile that logs into my home’s workstation.
From the shell, if I try to run nohup thunderbird &
what I’ll get is a notice that it can’t connect to my display and it exits. Well, that’s because I don’t have JuiceSSH doing any X forwarding, so the environment variable $DISPLAY
is unset.
nohup
launches its argument in such a way that prevents the subcommand from dying once the ssh TTY connection exits (it takes the typical IO streamsstdin
,stdout
, andstderr
and redirects the output streams tonohup.log
in the local folder).
The fix to the display issue is to simply say your display is the display of the running X process. In most cases, that’ll be :0.0
(it’ll be different if there are multiple users logged into the GUI or whatever; use system tools to find the one currently running).
export DISPLAY=:0.0 && nohup thunderbird &
That’s it. That adds the display variable to the environment and tells nohup
to run thunderbird
, which will pick up the DISPLAY
variable and draw its window on that display. The final ampersand backgrounds nohup
so you can go on with your day.
user@machine:~$ gnome-mahjongg
Unable to init server: Could not connect: Connection refused
(gnome-mahjongg:2651021): Gtk-WARNING **: 17:29:13.980: cannot open display:
user@machine:~$ pgrep gnome-mahjongg
user@machine:~$ echo $DISPLAY
user@machine:~$ export DISPLAY=:0.0 && nohup gnome-mahjongg &
[1] 2651154
user@machine:~$ nohup: ignoring input and appending output to 'nohup.out'
user@machine:~$ pgrep gnome-mahjongg
2651155
Here you see me trying to run gnome-mahjongg
on the command line. There’s no $DISPLAY
variable, so it fails. pgrep
shows there is no mahjongg running.
But, if I export the correct value for $DISPLAY
and wrap the game in a nohup
runner and send it to the background, gnome-mahjongg
starts and is now running on my workstation. I can either kill the process 2651155 here with the usual kill
tools (which exits the nohup
process running at 2651154), or I can just wait until I get home, unlock my screen, and click the X to close mahjongg after a few rousing games (for testing, of course).
This resolves a fear that I’ve held that I will be out of town and something will happen to make Thunderbird stop running my filters. All it takes is an app crash, an out-of-memory exception, a power outage, the PC rebooting on its own, whatever. Now, as long as X is running, I can send apps to its display. This fear is quelled.
Granted, this doesn’t resolve issues if X is running but I’m not logged in — like if the Gnome Greeter is waiting on me to login. That’s a different issue altogether. Maybe I’ll test that later! But let’s not worry about ourselves too much, eh? Baby steps.