Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Ubuntu Mate -- Reboot or Shutdown on Logoff?

Writer Sebastian Wright

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?

1 Answer

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy