-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedule_restart.cgi
67 lines (57 loc) · 1.82 KB
/
schedule_restart.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/perl
# schedule_restart.cgi
# Apply the scheduled restart
require "./paldmin-lib.pl";
require "./paldmin-ui-lib.pl";
ReadParse();
ui_print_header(undef, $text{"scheduler_schedule"}, "");
error_setup($text{"scheduler_err"});
# Update the cron job
$cron = foreign_installed("cron");
if (!$cron) {
error($text{"scheduler_ecron_missing"});
}
foreign_require("cron");
# Retrieve the job and overwrite values, or create new
@jobs = cron::list_cron_jobs();
my $cmd = "$module_config_directory/cron_restart.pl";
($job) = grep { $_->{"command"} eq $cmd } @jobs;
$oldjob = $job;
$job ||= { "command" => $cmd,
"user" => "root",
"active" => 1 };
cron::parse_times_input($job, \%in);
# Create a wrapper for the cron_restart.pl file
lock_file($cmd);
cron::create_wrapper($cmd, $module_name, "cron_restart.pl");
unlock_file($cmd);
# Lock the cron file and create entry into it or delete old entry
lock_file(cron::cron_file($job));
my $what = "";
if ($in{"sched"} && !$oldjob) {
# Need to create cron job
cron::create_cron_job($job);
$what = "scheduler_ccron";
} elsif (!$in{"sched"} && $oldjob) {
# Need to delete cron job
cron::delete_cron_job($job);
$what = "scheduler_dcron";
} elsif ($in{"sched"} && $oldjob) {
# Need to update cron job
cron::change_cron_job($job);
$what = "scheduler_ucron";
} else {
# Nothing really changed (stayed disabled)
$what = "scheduler_ncron";
}
unlock_file(cron::cron_file($job));
# Update the announcement
$config{"scheduler_announce"} = (%in{"scheduler_announce"} == 1 ? 1 : 0);
my $what_ann = ($config{"scheduler_announce"} == 1) ? "active" : "inactive";
save_module_config();
alert_box_with_collapsible(
($what eq "scheduler_ncron") ? "info" : "success",
$text{"scheduler_upd"},
$text{$what}."<br/>".text("scheduler_ann_result", $text{$what_ann})
);
ui_print_footer("", $text{"index_return"});