Closed felixonmars closed 10 years ago
What init system are you using? If you manually stop psd does it correctly kill the processes? As you can see, the kill_browsers function will try up to 5 times to kill a stuck process.
I am using systemd, it seems the 5 times is sufficient when I manually stop psd; but upon shutdown, maybe too many services are stopping at the same time, and it fails to stop the browser (I added a line of log to confirm this)
Hmm, it seems the two lines of SIGKILL are even not sufficient sometimes. I added a script (sorry in Python, I'm not really good at bash) to make sure to kill the browser before trying to stop psd:
$ cat /etc/systemd/system/kill-chromium.service
[Unit]
Description=Kill Chromium Before PSD Stop
After=psd.service
Requires=psd.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/true
ExecStop=/usr/local/bin/killchromium
[Install]
WantedBy=multi-user.target
$ cat /usr/local/bin/killchromium
#!/usr/bin/env python2
import sh
from time import sleep
i = 0
while True:
sh.pkill("-SIGTERM" if i < 10 else "-SIGKILL", "-u", "felix", "chromium", _ok_code=[0, 1])
try:
sh.pgrep("chromium")
except:
break
i += 1
sleep(0.05)
Hope this make sense.
As a workaround for you, that might be just fine but I would still like to identify the root cause of the issue on your system. The code as-is should do its job but does not.
Okay, thanks.
One more clue: Sometime when it screwed up, a "Crash Reports" directory will be in the same level as felix-chromium, so the whole directory looks like:
In ~/.config/chromium: felix-chromium -> /tmp/felix-chromium/ .flagged Crash Reports
Still looks like some sort of conflicts between psd's operation and chromium itself. From what I read from psd's code, the five times of pkill doesn't really ensure the process's exit, that's why I added the workaround for this...
Wish I could reproduce on my system... I am open to a "psd-native" method to kill an open browser. I just can't put your python code into the .service file.
Hmm, seems my workaround doesn't work that well too, I still get the same problem 4-5 times in the 3 days. I've tried some hacks around psd-resync service, and does not seem to have anything related to it.
I really appreciate your help, and I still want some more hints :P
Wish I had some ideas for you. I haven't seen this before.
Today I got time to debug it more - I added lots of logs into the code, and find out that every time when the problem happens, after the line mv "$DIR" "$BACKUP"
, $DIR was removed, but after rsync -aog --inplace --no-whole-file "$BACKUP/" "$VOLATILE/$user-$browser$suffix/"
(which has nothing to do with $DIR), the $DIR comes back as an empty directory.
So it has to be something else on startup that creates the dir. Finally I find a "/home/felix/.config/autostart/27B382D3E2467425101FF846CC90C9E516BAC5DE.chromium-service.desktop" file, even I've unchecked the background service option on chromium settings very long ago. After removing the .desktop file, the problem never occurs after a proper killing of browsers on shutdown.
I'll submit a PR about the killing part later, sorry :P
That finding in your ~/.config/autostart is crazy... what is the contents of the file? Do you know what created that file?
Seems chromium created the file itself. After a quick google I can find others have files of the same name-scheme too.
The content:
[Desktop Entry]
Type=Application
Terminal=false
Exec=/usr/lib/chromium/chromium --type=service
Name=Chromium Service
Wonder if this is due to chromium>advanced>System>Continue running background apps when Chromium is closed
EDIT: No, I cannot get chromium to create that .desktop file even with that option checked. Just a guess.
Is it safe to close this task as non-psd related?
Yeah, of course. Thanks a lot :)
Every time when powering off the machine, chromium will have several process remaining in
<defunct>
state, but psd only try to SIGTERM several times.After a restart, the file structure will be: ~/.config/chromium/felix-chromium -> /tmp/felix-chromium ~/.config/chromium/.flagged
And if I start chromium, a default profile will be created into ~/.config/chromium.
This has been noticed three times in a row. I've tried to add two pkill -SIGKILL lines under the notes:
This fixes the problem.