Add db-reconnect adminverb (#1398)

Adds a Reconnect-SQL verb to admins with permission flag R_DEBUG, as well as making the server attempt to automatically reconnect to SQL on connection drop.
This commit is contained in:
Lohikar
2017-01-05 15:39:01 -06:00
committed by skull132
parent bd9b5c1aea
commit 36a084fbbc
2 changed files with 30 additions and 4 deletions

View File

@@ -70,6 +70,10 @@ DBConnection/proc/Connect(dbi_handler = con_dbi, user_handler = con_user, passwo
DBConnection/proc/Disconnect()
return _dm_db_close(_db_con)
DBConnection/proc/Reconnect()
Disconnect()
Connect()
DBConnection/proc/IsConnected()
if(!config.sql_enabled)
return 0
@@ -122,8 +126,15 @@ DBQuery/proc/Execute(var/list/argument_list = null, var/pass_not_found = 0, sql_
var/result = _dm_db_execute(_db_query, sql_query, db_connection._db_con, cursor_handler, null)
if (ErrorMsg())
error("SQL Error: '[ErrorMsg()]'")
var/error = ErrorMsg()
if (error)
error("SQL Error: '[error]'")
// This is hacky and should probably be changed
if (error == "MySQL server has gone away")
log_and_message_admins("is attempting to reconnect the server to MySQL. (Connection Failure)")
dbcon.Reconnect()
if (db_connection.IsConnected())
src.Execute(argument_list)
return result

View File

@@ -199,7 +199,8 @@ var/list/admin_verbs_debug = list(
/client/proc/jumptomob,
/client/proc/jumptocoord,
/client/proc/dsay,
/client/proc/toggle_recursive_explosions
/client/proc/toggle_recursive_explosions,
/client/proc/restart_sql
)
var/list/admin_verbs_paranoid_debug = list(
@@ -1034,4 +1035,18 @@ var/list/admin_verbs_cciaa = list(
log_and_message_admins("admin-wiped [key_name_admin(target)]'s core.")
target.do_wipe_core()
/client/proc/restart_sql()
set category = "Debug"
set name = "Reconnect SQL"
set desc = "Causes the server to re-establish its connection to the MySQL server."
if (!check_rights(R_DEBUG))
return
if (alert("Reconnect to SQL?", "SQL Reconnection", "No", "No", "Yes") != "Yes")
return
log_and_message_admins("is attempting to reconnect the server to MySQL.")
dbcon.Reconnect()