mirror of
https://github.com/webmin/webmin.git
synced 2026-05-04 22:30:33 +01:00
Status monitor for minecraft server
This commit is contained in:
@@ -38,12 +38,7 @@ elsif ($err) {
|
||||
}
|
||||
|
||||
# Check if new version is out, if we haven't checked in the last 6 hours
|
||||
if (time() - $config{'last_check'} > 6*60*60) {
|
||||
my $sz = &check_server_download_size();
|
||||
$config{'last_check'} = time();
|
||||
$config{'last_size'} = $sz;
|
||||
&save_module_config();
|
||||
}
|
||||
&update_last_check();
|
||||
if ($config{'last_size'}) {
|
||||
my $jar = $config{'minecraft_jar'} ||
|
||||
$config{'minecraft_dir'}."/"."minecraft_server.jar";
|
||||
|
||||
@@ -293,3 +293,11 @@ log_atboot=Enabled server at boot time
|
||||
log_delboot=Disabled server at boot time
|
||||
log_enable_backup=Enabled scheduled backups to $1
|
||||
log_disable_backup=Disabled scheduled backups
|
||||
|
||||
monitor_up=Minecraft Server Alive
|
||||
monitor_latest=Minecraft Server Up To Date
|
||||
monitor_down=Server process is down
|
||||
monitor_noreply=Server is not responding
|
||||
monitor_notype=Unknown monitor type!
|
||||
monitor_newversion=New version is available
|
||||
monitor_nojar=JAR file $1 does not exist
|
||||
|
||||
@@ -244,18 +244,19 @@ if (!$nolog) {
|
||||
}
|
||||
}
|
||||
|
||||
# execute_minecraft_command(command, [no-log])
|
||||
# execute_minecraft_command(command, [no-log], [wait-time])
|
||||
# Run a command, and return output from the server log
|
||||
sub execute_minecraft_command
|
||||
{
|
||||
my ($cmd, $nolog) = @_;
|
||||
my ($cmd, $nolog, $wait) = @_;
|
||||
$wait ||= 100;
|
||||
my $logfile = $config{'minecraft_dir'}."/server.log";
|
||||
my $fh = "LOG";
|
||||
&open_readfile($fh, $logfile);
|
||||
seek($fh, 0, 2);
|
||||
my $pos = tell($fh);
|
||||
&send_server_command($cmd, $nolog);
|
||||
for(my $i=0; $i<100; $i++) {
|
||||
for(my $i=0; $i<$wait; $i++) {
|
||||
select(undef, undef, undef, 0.1);
|
||||
my @st = stat($logfile);
|
||||
last if ($st[7] > $pos);
|
||||
@@ -645,7 +646,7 @@ my $dir = strftime($config{'backup_dir'}, @tm);
|
||||
|
||||
# Create destination dir
|
||||
if (!-d $dir) {
|
||||
if (!&make_dir($dir, 0700)) {
|
||||
if (!&make_dir($dir, 0755)) {
|
||||
&send_backup_email(
|
||||
"Failed to create destination directory $dir : $!");
|
||||
return;
|
||||
@@ -676,6 +677,7 @@ foreach my $w (@worlds) {
|
||||
"cd ".quotemeta($config{'minecraft_dir'})." && ".
|
||||
"zip -r ".quotemeta($file)." ".quotemeta($w->{'name'}));
|
||||
my $ex = $?;
|
||||
&set_ownership_permissions(undef, undef, 0755, $file);
|
||||
if ($w->{'name'} eq $def &&
|
||||
&is_minecraft_server_running()) {
|
||||
# Re-enable world writes
|
||||
@@ -741,4 +743,16 @@ for(my $i=0; $i<@xpmap; $i+=2) {
|
||||
return undef;
|
||||
}
|
||||
|
||||
# update_last_check()
|
||||
# If the last check time is too old, check for the latest version
|
||||
sub update_last_check
|
||||
{
|
||||
if (time() - $config{'last_check'} > 6*60*60) {
|
||||
my $sz = &check_server_download_size();
|
||||
$config{'last_check'} = time();
|
||||
$config{'last_size'} = $sz;
|
||||
&save_module_config();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
68
minecraft/status_monitor.pl
Executable file
68
minecraft/status_monitor.pl
Executable file
@@ -0,0 +1,68 @@
|
||||
|
||||
do 'minecraft-lib.pl';
|
||||
|
||||
# status_monitor_list()
|
||||
# Return a list of supported monitor types
|
||||
sub status_monitor_list
|
||||
{
|
||||
return ( [ "minecraft_up", $text{'monitor_up'} ],
|
||||
[ "minecraft_latest", $text{'monitor_latest'} ] );
|
||||
}
|
||||
|
||||
# status_monitor_status(type, &monitor, from-ui)
|
||||
# Check the drive status
|
||||
sub status_monitor_status
|
||||
{
|
||||
my ($type, $monitor, $fromui) = @_;
|
||||
if ($type eq "minecraft_up") {
|
||||
# Check if server is running and can reply to commands
|
||||
if (!&is_minecraft_server_running()) {
|
||||
return { 'up' => 0,
|
||||
'desc' => $text{'monitor_down'} };
|
||||
}
|
||||
my $out = &execute_minecraft_command("/seed", 0, 5);
|
||||
if ($out !~ /^\d+/) {
|
||||
return { 'up' => 0,
|
||||
'desc' => $text{'monitor_noreply'} };
|
||||
}
|
||||
return { 'up' => 1 };
|
||||
}
|
||||
elsif ($type eq "minecraft_latest") {
|
||||
# Compare version with latest available to download
|
||||
&update_last_check();
|
||||
if ($config{'last_size'}) {
|
||||
my $jar = $config{'minecraft_jar'} ||
|
||||
$config{'minecraft_dir'}."/"."minecraft_server.jar";
|
||||
my @st = stat($jar);
|
||||
if (@st && $st[7] != $config{'last_size'}) {
|
||||
return { 'up' => 0,
|
||||
'desc' => $text{'monitor_newversion'} };
|
||||
}
|
||||
elsif (!@st) {
|
||||
return { 'up' => -1,
|
||||
'desc' => &text('monitor_nojar', $jar) };
|
||||
}
|
||||
}
|
||||
return { 'up' => 1 };
|
||||
}
|
||||
else {
|
||||
return { 'up' => -1,
|
||||
'desc' => $text{'monitor_notype'} };
|
||||
}
|
||||
}
|
||||
|
||||
# status_monitor_dialog(type, &monitor)
|
||||
# Return form for selecting a drive
|
||||
sub status_monitor_dialog
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
|
||||
# status_monitor_parse(type, &monitor, &in)
|
||||
# Parse form for selecting a rule
|
||||
sub status_monitor_parse
|
||||
{
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
Reference in New Issue
Block a user