Adds kill process button to dashboard.

This commit is contained in:
Andrew 2021-09-13 15:03:47 -04:00
parent 2528c123f2
commit 7316cc7ea0
6 changed files with 93 additions and 7 deletions

View File

@ -362,6 +362,9 @@ class Server:
else:
return False
def get_pid(self):
return self.PID
def detect_crash(self):
logger.info("Detecting possible crash for server: {} ".format(self.name))

View File

@ -2,6 +2,7 @@ import json
import logging
import tempfile
import threading
from typing import Container
import zipfile
import tornado.web
@ -197,6 +198,18 @@ class AjaxHandler(BaseHandler):
self.redirect("/panel/server_detail?id={}&subpage=files".format(server_id))
return
elif page == "kill":
server_id = self.get_argument('id', None)
svr = self.controller.get_server_obj(server_id)
if svr.get_pid():
try:
svr.killpid(svr.get_pid())
except Exception as e:
logger.error("Could not find PID for requested termsig. Full error: {}".format(e))
else:
logger.error("Could not find PID for requested termsig. Full error: {}".format(e))
return
@tornado.web.authenticated
def delete(self, page):
if page == "del_file":

View File

@ -126,13 +126,15 @@
<td id="controls{{server['server_data']['server_id']}}" class="actions_serverlist">
{% if server['user_command_permission'] %}
{% if server['stats']['running'] %}
<a class="stop_button" data-id="{{server['server_data']['server_id']}}"> <i class="fas fa-stop"></i></a> &nbsp;
<a class="restart_button" data-id="{{server['server_data']['server_id']}}"> <i class="fas fa-sync"></i></a> &nbsp;
<a class="stop_button" data-id="{{server['server_data']['server_id']}}" data-toggle="tooltip" title={{ translate('dashboard', 'stop') }}> <i class="fas fa-stop"></i></a> &nbsp;
<a class="restart_button" data-id="{{server['server_data']['server_id']}}" data-toggle="tooltip" title={{ translate('dashboard', 'restart') }}> <i class="fas fa-sync"></i></a> &nbsp;
<a class="kill_button" data-id="{{server['server_data']['server_id']}}" class="kill_button" data-toggle="tooltip" title={{ translate('dashboard', 'kill') }}> <i class="fas fa-skull"></i></a> &nbsp;
{% elif server['stats']['updating']%}
<a data-id="{{server['server_data']['server_id']}}" class=""> UPDATING...</i></a>
{% else %}
<a data-id="{{server['server_data']['server_id']}}" class="play_button"><i class="fas fa-play"></i></a> &nbsp;
<a data-id="{{server['server_data']['server_id']}}" class="clone_button"> <i class="fas fa-clone"></i></a>&nbsp;
<a data-id="{{server['server_data']['server_id']}}" class="play_button"><i class="fas fa-play" data-toggle="tooltip" title={{ translate('dashboard', 'start') }}></i></a> &nbsp;
<a data-id="{{server['server_data']['server_id']}}" class="clone_button"> <i class="fas fa-clone" data-toggle="tooltip" title={{ translate('dashboard', 'clone') }}></i></a>&nbsp;
<a class="kill_button" data-id="{{server['server_data']['server_id']}}" class="kill_button" data-toggle="tooltip" title={{ translate('dashboard', 'kill') }}> <i class="fas fa-skull"></i></a> &nbsp;
{% end %}
{% end %}
</td>
@ -240,6 +242,25 @@ function send_command (server_id, command){
});
}
function send_kill (server_id){
/* this getCookie function is in base.html */
var token = getCookie("_xsrf");
$.ajax({
type: "POST",
headers: {'X-XSRFToken': token},
url: '/ajax/kill?id=' + server_id,
success: function(data){
console.log("got response:");
console.log(data);
setTimeout(function(){
location.reload();
}, 10000);
}
});
}
$( document ).ready(function() {
console.log('ready for JS!')
@ -272,6 +293,37 @@ $( document ).ready(function() {
title: '{% raw translate("dashboard", "sendingCommand") %}',
message: '<div align="center"><i class="fas fa-spin fa-spinner"></i> &nbsp; {% raw translate("dashboard", "bePatientRestart") %} </div>'
});
});
$( ".kill_button" ).click(function() {
server_id = $(this).attr("data-id");
bootbox.confirm({
message: "This will kill the server process and all it's subprocesses. Killing a process can potentially corrupt files. Only do this in extreme circumstances. Are you sure you would like to continue?",
buttons: {
confirm: {
label: '{% raw translate("dashboard", "kill") %}',
className: 'btn-danger'
},
cancel: {
label: '{% raw translate("panelConfig", "cancel") %}',
className: 'btn-secondary'
}
},
callback: function (result) {
if(result){
send_kill(server_id);
var dialog = bootbox.dialog({
title: '{% raw translate("dashboard", "killing") %}',
message: '<p><i class="fa fa-spin fa-spinner"></i> Loading...</p>'
});
dialog.init(function(){
setTimeout(function(){
location.reload();
}, 15000);
});
}
}
});
});
if (webSocket) {
cpu_data = document.getElementById('cpu_data');

View File

@ -89,7 +89,13 @@
"sendingCommand": "Sending your command",
"cpuCurFreq": "CPU Current Clock",
"cpuMaxFreq": "CPU Maximum Clock",
"cpuCores": "CPU Cores"
"cpuCores": "CPU Cores",
"start": "Start",
"stop": "Stop",
"clone": "Clone",
"kill": "Kill Process",
"restart": "Restart",
"killing": "Killing process..."
},
"accessDenied": {
"accessDenied": "Access Denied",

View File

@ -89,7 +89,13 @@
"sendingCommand": "Lähetämme komentoasi",
"cpuCurFreq": "Nykyinen kellotaajuus",
"cpuMaxFreq": "Maksimi kellotaajuus",
"cpuCores": "Suorittimen ytimet"
"cpuCores": "Suorittimen ytimet",
"start": "Start",
"stop": "Stop",
"clone": "Clone",
"kill": "Kill Process",
"restart": "Restart",
"killing": "Killing process..."
},
"accessDenied": {
"accessDenied": "Käyttö estetty",

View File

@ -89,7 +89,13 @@
"sendingCommand": "Envoi de votre commande",
"cpuCurFreq": "Fréquence CPU actuelle",
"cpuMaxFreq": "Fréquence CPU Maximum",
"cpuCores": "Coeurs CPU"
"cpuCores": "Coeurs CPU",
"start": "Start",
"stop": "Stop",
"clone": "Clone",
"kill": "Kill Process",
"restart": "Restart",
"killing": "Killing process..."
},
"accessDenied": {
"accessDenied": "Accès Interdit",