Feedback

type to search

Scheduled reboot that can be cancelled by desktop user?

Asked by [ Editor ] , Edited by vrkalak [ Moderator ]

How to trigger a system reboot and still allow a logged in Gnome Desktop user to cancel it? Purpose is for a scheduled reboot of a workstation that can be cancelled by the current user. I am thinking that a DBUS message could trigger Gnome Power Manager to prompt the user.

Ultimately I want to be able to detect if a user is logged in to the desktop(ck-list-sessions) and if so prompt to user about the reboot, else run ‘reboot’ . I wish that this was possible: gnome-session-save —reboot-dialog

or Cancel

3 answers

1

depaloan [ Editor ]

You could schedule another job to check if a reboot is scheduled in a few minutes and if a user is currently logged in; if this condition is achieved then send a notification to the logged user (via zenity) giving him the possibility to abort the reboot.

Instead of DBus you could use a simple lock/run/text file inside /var: both jobs (the reboot one and the check one) should read it; the check job should write some values inside it to let the check job know to abort the reboot.

I know it’s an hackish solution but it should work.

or Cancel
0

amlj [ Editor ]

Hmm… Not sure what you can do here… But you can try to install gnome-scheduler, which is a good tool for GNOME desktop… Then add the users to sudoers file.
After that, make a script like this:

read -p “Would you like to reboot? Tip: Type Y (if yes) or N (if no)” CHOICE

if [ $CHOICE = ‘Y’ ]
then
sudo init 6
fi

if [ $CHOICE = ‘N’ ]
then
echo “OK!”
fi

And then:
chmod 700 FILE

After that, give the path to the file, as the command which should be executed…

The bad thing about this, is that I think it will not work if a user is not logged in... Anyway, I don't know how this works... But maybe, you can at least use some solutions together and work something out...

It will just work if a user is logged in GNOME right now... If a user is logged in, they'll see a new shell, which is asking them if they'd like to reboot, and they can answer Y or N.

or Cancel
0

emeitner [ Editor ]

My solution is:

#!/usr/bin/perl -w

use strict;

my $session_list = `/usr/bin/ck-list-sessions`;
my = split /^Session/m,$session_list;
my $active_x;
my %x_sessions;

foreach my $session ( )
{
  next if $session =~ /session-type = 'LoginWindow'/;
  $session =~ /x11-display = '([^']+)'/;
  my $display = $1;
  if( $display )
  {
    $session =~ /unix-user = '([^']+)'/;
    my $user = $1;
    $x_sessions{$display} = $user;
    next if( $session =~ /active = FALSE/);
    $active_x = $display;
  }
}

  
if( $active_x )
{
  $ENV{'DISPLAY'} = $active_x;
  my $uname = getpwuid( $x_sessions{$active_x} );
  system( "zenity"
    ,"--question"
    ,"--text=This computer is scheduled to restart at this time. You may choose to prevent this if you wish.\n\nIf you take no action this computer will restart in one minute!"
    ,"--ok-label=Restart"
    ,"--cancel-label=NO!"
    ,"--title=Restart requested"
    ,"--timeout=10" );

  if ( $? >> 8 == 1 )
  {
    system("logger","-t","nice-reboot","$uname chose to cancel the reboot.");
    exit;
  }
}

for my $display ( keys %x_sessions )
{
  $ENV{'DISPLAY'} = $display;  
  my $uname = getpwuid( $x_sessions{$display} );
  system("logger","-t","nice-reboot","Logging out $uname.");
  system("sudo","-u",$uname,"gnome-session-save", "--force-logout");
}

sleep 30;
system("logger","-t","nice-reboot","Rebooting now");
system("reboot");

This gets scheduled to run as root at some time.

While I suspect that this same thing can be triggered in Gnome Power Manager via a DBUS call, that elegant solution may have to wait.

or Cancel

Your answer

You need to join Debian to complete this action, click here to do so.