-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron_restart.pl
61 lines (51 loc) · 1.45 KB
/
cron_restart.pl
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
#!/usr/bin/perl
# cron_restart.pl
# Called by cron to restart the server
# If called with announce on, restart is delay and broadcast messages are sent
# if RCON is valid and enabled
$no_acl_check++;
require "./paldmin-lib.pl";
require "./rcon-lib.pl";
init_service();
init_rcon();
if ($config{'scheduler_announce'} != 1) {
print STDOUT "Skipping announcement: Announcement not set.\n";
goto RESTART;
}
if (!is_server_running()) {
print STDOUT "Skipping announcement: Server not running.\n";
goto RESTART;
}
if (!$rcon{"valid"}) {
print STDOUT "Skipping announcement: RCON Setup is no valid:\n";
print STDOUT $rcon{"msg"}{"content"}."\n";
goto RESTART;
}
my ($ok, $exec, $output) = broadcast("Scheduled Restart in 15min...");
if (!$ok) {
print STDOUT "Skipping announcement: Failed to make announcement #1.\n";
goto RESTART;
}
sleep(5 * 60);
($ok, $exec, $output) = broadcast("Scheduled Restart in 10min...");
if (!$ok) {
print STDOUT "Skipping announcement: Failed to make announcement #2.\n";
goto RESTART;
}
sleep(5 * 60);
($ok, $exec, $output) = broadcast("Scheduled Restart in 5min...");
if (!$ok) {
print STDOUT "Skipping announcement: Failed to make announcement #3.\n";
goto RESTART;
}
sleep(4 * 60);
($ok, $exec, $output) = broadcast("Scheduled Restart in 1min...");
if (!$ok) {
print STDOUT "Skipping announcement: Failed to make announcement #4.\n";
goto RESTART;
}
sleep(60);
RESTART:
print STDOUT "Restarting server...";
restart_server();
exit(0);