Code

uncomment needed line in triggered_action_reboot
[gosa.git] / gosa-si / client / events / gosaTriggered.pm
1 package gosaTriggered;
2 use Exporter;
3 @ISA = qw(Exporter);
4 my @events = (
5     "get_events",
6     "trigger_action_localboot",
7     "trigger_action_halt",
8     "trigger_action_faireboot",
9     "trigger_action_reboot",
10     "trigger_action_memcheck",
11     "trigger_action_reinstall",
12     "trigger_action_update",
13     "trigger_action_instant_update",
14     "trigger_action_sysinfo",
15     );
16 @EXPORT = @events;
18 use strict;
19 use warnings;
20 use GOSA::GosaSupportDaemon;
22 BEGIN {}
24 END {}
27 sub get_events { return \@events; }
30 sub trigger_action_localboot {
31     my ($msg, $msg_hash) = @_;
32     my $timeout;
34     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
35         $timeout = -1;
36     } 
37     else {
38         $timeout = @{$msg_hash->{timeout}}[0];
39     }
41     # check logged in user
42     my $logged_in_user = 1;
43     if( $logged_in_user ) {
44         # TODO do something
45     }
46     else {
47         $timeout = 0;
48     }
49         
50     # execute function
51     if( $timeout == 0 ) {
52         print STDERR ("shutdown -r +$timeout\n");
53     }
54     elsif( $timeout > 0 ) {
55         print STDERR ("shutdown -r +$timeout\n");
56     }
57     elsif( $timeout < 0 ) {
58         print STDERR "The administrator has sent a signal to reboot this workstation. It will reboot after you've logged out.\n";
59         open(FILE, "> /etc/gosa-si/event");
60         print FILE "trigger_action_localboot\n";
61         close(FILE);
62     }
63     else {
64         # TODO do something, error handling, logging
65     }
67     return;
68 }
71 sub trigger_action_faireboot {
72     my ($msg, $msg_hash) = @_;
73         &main::daemon_log("DEBUG: run /usr/sbin/faireboot\n", 7); 
74     system("/usr/sbin/faireboot");
75     return;
76 }
79 sub trigger_action_reboot {
80     my ($msg, $msg_hash) = @_;
81     my $timeout;
83     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
84         $timeout = 0;
85     } 
86     else {
87         $timeout = @{$msg_hash->{timeout}}[0];
88     }
90     # check logged in user
91     my @user_list = &get_logged_in_users;
92     if( @user_list >= 1 ) {
93         system( "/usr/bin/goto-notify reboot" );
94         open(FILE, "> /etc/gosa-si/event");
95         print FILE "reboot\n";
96         close(FILE);
97     }
98     else {
99         system( "/sbin/shutdown -r +$timeout &" );
100     }
102     return;
106 sub trigger_action_halt {
107     my ($msg, $msg_hash) = @_;
108     my $timeout;
110     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
111         $timeout = 0;
112     } 
113     else {
114         $timeout = @{$msg_hash->{timeout}}[0];
115     }
117     # check logged in user
118     my @user_list = &get_logged_in_users;
119     if( @user_list >= 1 ) {
120         system( "/usr/bin/goto-notify halt" );
121         open(FILE, "> /etc/gosa-si/event");
122         print FILE "halt\n";
123         close(FILE);
124     }
125     else {
126         system( "/sbin/shutdown -h +$timeout &" );
127     }
129     return;
133 sub trigger_action_reinstall {
134     my ($msg, $msg_hash) = @_;
136     # check logged in user
137     my @user_list = &get_logged_in_users;
138     if( @user_list >= 1 ) {
139         system( "/usr/bin/goto-notify install" );
140         open(FILE, "> /etc/gosa-si/event");
141         print FILE "install\n";
142         close(FILE);
143     }
144     else {
145         system( "/sbin/shutdown -r now &" );
146     }
148     return;
152 # Backward compatibility
153 sub trigger_action_update {
154     my ($msg, $msg_hash) = @_;
156     # Execute update
157     system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai-softupdate &" );
159     return;
162 # Backward compatibility
163 sub trigger_action_instant_update {
164     my ($msg, $msg_hash) = @_;
166     # Execute update
167     system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai-softupdate &" );
169     return;
173 1;