Graceful shutdown in ArchLinux

8,362

Solution 1

This worked for me on my Arch Linux with Gnome 3.12. It turned out that it maybe related to the config in /etc/gdm/PostSession/Default.

  1. Run sudo pacman -S wmctrl to install wmctrl for windows management.

  2. Create a executable file for closing all windows. For example, I put it in /home/[your_username]/bin/close-all-windows with these contents:

    #!/bin/sh
    wmctrl -l | while read -r line
    do
        wmctrl -c `echo "$line" | sed 's/.*  [0-9]* [your_hostname] //'`
    done
    
  3. Modify /etc/gdm/PostSession/Default and add these contents before exit 0:

    echo " Closing selected windows programs gracefully"
    export DISPLAY=:0
    su [your_username] -c /home/[your_username]/bin/close-all-windows
    

Hope these will work.

Solution 2

To gracefully shutdown your desktop, you may need to raise the TimeoutStopSec= for GDM, or whatever other display manager you are using.

Share:
8,362

Related videos on Youtube

Jean Felipe
Author by

Jean Felipe

I've a 20y experience in the eLearning and Computer Based Training, with a special focus on aviation (pilots and maintenance staff) training. I've good design and programming skill, including the following languges and toolkits, tools and Operarting Systems: Java (special focus on server side and client side cross-platform development and deployment) JavaScript / HTML5 / CSS3 (special focus on cross browser and cross devices development and optimizations for Mobile) C# C++ / Vala C / Objective-C PHP SQL SWT, GTK+, Cocoa ANT Flash and ActionScript 3 and 2 Inkscape, Gimp, Photoshop etc 3D Studio Max and Blender (basic) Linux, Windows, OS X, Android an iOS SVN, GIT Bugzilla, Mantis, JIRA I've a long experience in team working and management, software management, bug tracking and quality assurance, customer relationship management and problem solving. I'm a big fan of the OpenSource world and GNU/Linux. Most of my knowledge and skills come from passion, self-training and direct experience. SOreadytohelp

Updated on September 18, 2022

Comments

  • Jean Felipe
    Jean Felipe over 1 year

    I'm trying to get a graceful shutdown/reboot in ArchLinux with GNOME Shell. Now, when I ask for shut-down, it immediately shuts down without giving open programs time to gracefully close / save open files. As a result, whenever I restart Chrome (for example) it tells me that the session was not closed correctly etc. By reading on the web I learnt that systemd while shutting down processes, it first send a SIGTERM followed by SIGKILL if the process does not close withing a given timeout. However I notice that on my system SIGKILL is sent immediately after SIGTERM and I guess this is the cause of a non graceful programs termination.

    I've found some documentation which (if I read it correctly) states that timeout before sending SIGKILL can be set by TimeoutStopSec= option. Also sending SIGKILL could also be disabled by SendSIGKILL= option. But I cannot find where to configure those options... is there a systemd shutdown / reboot configurations file where I can set those options?

    EDIT:

    I did some test and I discovered two interesting things:

    1. If I manually close chrome like this killall -SIGTERM chrome, it will not complain that is has not been closed correctly next time I start it again. If I close it like this instead killall -SIGKILL chrome, it will complain. This tells me that chrome is handling SIGTERM correctly.
    2. Looking at the output of my shutdown procedure, systemd prints Sending SIGTERM... immediately followed by Sending SIGKILL...

    According to comment below, systemd is handling its processes only. So in my case GDM. This tells me that the issue could be:

    1. either GDM not closing it's child processes (e.g. Chrome) correctly (i.e. by sending SIGTERM to them)
    2. or systemd is sending GDM a SIGKILL message to early not giving it the time to correctly close its children.

    Is there a way to check/configure how actually GDM closes its children?

    • phemmer
      phemmer about 10 years
      Systemd only signals processes directly under it's control. Things like chrome are not one of those processes. Systemd will signal your display manager (xdm, gdm, kdm, whatever), it's then up to the display manager to signal its children, and so on down the line until you get to chrome. If nothing signals chrome, it dies when the xorg server is shut down and it's display goes away.
    • Jean Felipe
      Jean Felipe about 10 years
      @Patrick: thanks, I guessed so. That's why I tried adding 'TimeoutStopSec=90s' to '[Service]' section of ' /etc/systemd/system/display-manager.service' according to this: freedesktop.org/software/systemd/man/systemd.service.html but nothing changes... :(
    • mikeserv
      mikeserv about 10 years
      Chrome should be under systemd's control - systemd is pid 1 - but Chrome execs out of its wrapper script in a subshell and invokes child processes afterward. Still, it will do what it needs to kill its zygotes so long as your system is properly configured. Are you using one of those temp-space solutions for chrome that you'll find recommended in the Arch wiki?
    • Jean Felipe
      Jean Felipe about 10 years
      @mikeserv: I've installed chrome from AUR through yaourt. I don't know about those 'temp-space solutions for chrome' that you're mentioning. Can you give me some link plz?
    • mikeserv
      mikeserv about 10 years
      No, you're not. Though they'd likely help - Chrome keeps a lot of data in its own virtual database filesystem... Here's my own solution, but no warranties, man: gdriv.es/mikeserv/scripts/google-chrome-beta.bash
    • StrongBad
      StrongBad about 10 years
      I run into a similar problem with KDE and Firefox on Arch. I have never gotten around to trying to figure out why.
    • DBedrenko
      DBedrenko about 10 years
      Relevant thread with explanations here: bbs.archlinux.org/viewtopic.php?id=170171 Looks like we have to use a script like in the thread linked in the last post.
    • user2914606
      user2914606 almost 10 years
      GDM is not signaling processes. GDM is essentially a dumb way to hook up Xorg and PAM. the real culprit is gnome-session.
  • AF7
    AF7 about 8 years
    For Plasma 5, putting this script in .config/plasma-workspace/shutdown/ solves the problem
  • enigmaticPhysicist
    enigmaticPhysicist about 8 years
    Seems to me GDM should never have told systemd to shut down in the first place if it didn't know whether all clients could be closed.
  • Admin
    Admin almost 2 years
    Yes this seems like a bug. There should be a configurable option. maybe gdm can use systemd to launch processes? idk...