Ubuntu: Ubuntu Mate — Reboot or Shutdown on Logoff?



Question:

I'm using Ubuntu Mate 16.04. I would like to configure the system so that it reboots or shuts down on logoff. Here's what I have done so far:

I created /etc/lightdm/lightdm.conf.d/50-ubuntu-mate.conf with the following content.

  [Seat:*]  user-session=mate  session-cleanup-script=/sbin/reboot  allow-guest=false  

While this successfully reboots the machine on logoff, I have one problem with it. It also reboots the machine when I am at the login greeter and I select a different user account for login. I do not want to reboot when I'm not actually logged into an account and all I am doing is selecting a user from the drop down to login as.

Can anyone tell me if there is another way to go about this that does not cause reboots from the login greeter?


Solution:1

Track whether or not we are coming from a user session

I'm posting an answer to my own question here. If anyone has other solutions, I'd love to see them.

Solution overview
It's not enough to check and see if anyone is logged in when the session-cleanup-script runs because, this script runs after users have been completely logged out. I decided to go about tracking this like so.

  • Use greeter-setup-script to set a temporary file on login
  • When running session-cleanup-script, check to see if the file exists.
    • If it does, preform reboot/shutdown
    • If it does not, terminate script without reboot/shutdown

Example configuration
Example /etc/lightdm/lightdm.conf.d/50-ubuntu-mate.conf file

  [Seat:*]  user-session=mate  greeter-setup-script=/path/to/greeter-setup.sh  session-cleanup-script=/path/to/session-cleanup.sh    # ... (other settings)  

Example greeter-setup.sh script

#!/bin/bash    # Start watching for login and on login, set a status file  (      while [ $(who | grep "(:0)" | wc -l) -eq 0 ]      do          sleep 1      done      touch /tmp/loggedIn  ) &      # ... do anything else that needs to be done when the greeter starts  

Example session-cleanup.sh script

#!/bin/bash    # Check the status file. If it exists, remove it and continue the script.  # If it does not exist, drop out of the script.  [ -e /tmp/loggedIn ] && rm /tmp/loggedIn || exit    # ... do whatever else needs to be done when sessions end  # in my case this amounts to ...  /sbin/shutdown -h 0  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »