Cleanly close Thunderbird from the command line?

Discussion of features in Mozilla Thunderbird
Locked
Luke276
Posts: 5
Joined: January 8th, 2006, 7:26 pm

Cleanly close Thunderbird from the command line?

Post by Luke276 »

I often run thunderbird over ssh, remotely logging into my Ubuntu 7.10 PC. Sometimes, I'll have left Thunderbird running, and will either have to kill Thunderbird (and clean up the locks) , or just wait till I get back home. Is there a way to cleanly close all instances of Thunderbird currently running? Would a script that killed Thunderbird and removed the locks essentially do the same thing? I'm a little worried that there might be something else that isn't cleaned up properly (and of course there's always the worry Thunderbird is doing something when I kill it.)
User avatar
Rod Whiteley
Posts: 11480
Joined: December 6th, 2004, 3:41 am
Location: UK

Post by Rod Whiteley »

If you simply kill it, then Thunderbird does not write some things back to disk. For example, you could lose some settings changes. But there does not seem to be a way to close it cleanly from a command line.

As an experiment, I added support for a command line -quit switch in my Mail Tweak extension. I have no idea whether it will work in your situation.
Last edited by Rod Whiteley on June 13th, 2008, 5:19 am, edited 1 time in total.
Rod
rsx11m
Moderator
Posts: 14404
Joined: May 3rd, 2007, 7:40 am
Location: US

Post by rsx11m »

Sending the process a SIGHUP works for me (process ID obtained from "lock" symlink), giving the same result as logging out while it is running, and also cleaning up the locks. But then, I'm using the customized RPM's from SuSE, so maybe something works differently in Ubuntu.
klades
Posts: 855
Joined: May 3rd, 2004, 1:20 pm
Contact:

Post by klades »

By default "kill" command should send a "SIGTERM" signal, so the process should be terminated cleanly.
See "man kill" and "man signal" and http://en.wikipedia.org/wiki/SIGTERM
User avatar
Rod Whiteley
Posts: 11480
Joined: December 6th, 2004, 3:41 am
Location: UK

Post by Rod Whiteley »

I tried it on Ubuntu. SIGTERM and SIGHUP both caused settings changes to be lost, although the profile lock was cleared.
Rod
rsx11m
Moderator
Posts: 14404
Joined: May 3rd, 2007, 7:40 am
Location: US

Post by rsx11m »

You are right, it's not updating prefs.js and some other files in the profile when closed this way. This appears to be a known issue, I found a fairly old enhancement request to be able to close Mozilla from the command line and about not updating things correctly if shut down by a signal. I would consider it rather a bug though if SIGTERM and SIGHUP are not honored in the way they should, like shutting down the application similar to normally closing it...
klades
Posts: 855
Joined: May 3rd, 2004, 1:20 pm
Contact:

Post by klades »

Rod Whiteley, I think to have found a "quit" routine working.
Could you tell me which settings exactly are lost if you kill Thunderbird from the command line with SIGHUP or SIGTERM?
User avatar
Rod Whiteley
Posts: 11480
Joined: December 6th, 2004, 3:41 am
Location: UK

Post by Rod Whiteley »

I did not investigate fully. I think normally Thunderbird may write localstore.rdf when a window closes, and prefs.js when the application closes, but there might be others—for example, I do not know when add-ons change requests are written so that they can be completed on the next restart.

Mail Tweak looks for a window containing goQuitApplication, and calls it, but it might not always succeed:
http://lxr.mozilla.org/seamonkey/source ... rlay.js#49
Rod
klades
Posts: 855
Joined: May 3rd, 2004, 1:20 pm
Contact:

Post by klades »

Hello again Rod.
Which version of Mail Tweak has this option? If it has not been released yet, could I try it?
In my test, I've tried to use "goQuitApplication" function, but I always had "zombie" processes (on Windows, no test yet on Linux). Maybe your method has fixed this problem.
It seems to work better enumerate open windows and close them with "close()" method called with setTimeout, but I must investigate more about it.
User avatar
Rod Whiteley
Posts: 11480
Joined: December 6th, 2004, 3:41 am
Location: UK

Post by Rod Whiteley »

I sent you a private message. I did not try to fix any problems in goQuitApplication. Enumerating windows and closing them is exactly what it does: http://lxr.mozilla.org/seamonkey/source ... up.cpp#258
Rod
klades
Posts: 855
Joined: May 3rd, 2004, 1:20 pm
Contact:

Post by klades »

I tried your test version, but in Linux I get this error:

Code: Select all

The program 'thunderbird-bin' received an X Window System error.


Instead with this code, it seems to work on Linux and gives no "zombie" process on win:

Code: Select all

var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].
    getService(Components.interfaces.nsIWindowWatcher);
var enum = ww.getWindowEnumerator();
   while (enum.hasMoreElements()) {
      var w = enum.getNext()
   w.setTimeout("window.close()", 2000);
}


With this code, the shutdown seems to be clean.
But it should be more tested...
Ciao, Paolo
szbzhao
New Member
Posts: 1
Joined: December 23rd, 2017, 9:35 pm

Re: Cleanly close Thunderbird from the command line?

Post by szbzhao »

to All,

I currently use these commands to do that successfully from ssh command line:
1. DISPLAY=:0.0 xdotool search --onlyvisible --name thunderbird # it show me the window id
2. DISPLAY=:0.0 wmctrl -ic window_id

I not really sure if the command it can work reliably.
User avatar
LIMPET235
Moderator
Posts: 39932
Joined: October 19th, 2007, 1:53 am
Location: The South Coast of N.S.W. Oz.

Re: Cleanly close Thunderbird from the command line?

Post by LIMPET235 »

Locking due to very old age.
[Ancient Amateur Astronomer.]
Win-10-H/64 bit/500G SSD/16 Gig Ram/450Watt PSU/350WattUPS/Firefox-115.0.2/T-bird-115.3.2./SnagIt-v10.0.1/MWP-7.12.125.

(Always choose the "Custom" Install.)
Locked