add restart services
restart services from status page
This commit is contained in:
parent
2d5e4e17a0
commit
c77f464c9d
3 changed files with 117 additions and 31 deletions
|
|
@ -198,8 +198,7 @@ class ConfServer:
|
||||||
|
|
||||||
async def handle_base(self, request):
|
async def handle_base(self, request):
|
||||||
try:
|
try:
|
||||||
# TODO - API Options here for viewing clients, tokens, restarting the server, etc.
|
|
||||||
# text = "Bumper!"
|
|
||||||
bots = bumper.db_get().table("bots").all()
|
bots = bumper.db_get().table("bots").all()
|
||||||
clients = bumper.db_get().table("clients").all()
|
clients = bumper.db_get().table("clients").all()
|
||||||
helperbot = bumper.mqtt_helperbot.Client.session.transitions.state
|
helperbot = bumper.mqtt_helperbot.Client.session.transitions.state
|
||||||
|
|
@ -331,18 +330,27 @@ class ConfServer:
|
||||||
async def restart_Helper(self):
|
async def restart_Helper(self):
|
||||||
|
|
||||||
await bumper.mqtt_helperbot.Client.disconnect()
|
await bumper.mqtt_helperbot.Client.disconnect()
|
||||||
await bumper.mqtt_helperbot.start_helper_bot()
|
asyncio.create_task(bumper.mqtt_helperbot.start_helper_bot())
|
||||||
|
|
||||||
async def restart_MQTT(self):
|
async def restart_MQTT(self):
|
||||||
mqttserver = bumper.mqtt_server.broker
|
|
||||||
|
|
||||||
await bumper.mqtt_server.broker.shutdown()
|
if not (bumper.mqtt_server.broker.transitions.state == "stopped" or bumper.mqtt_server.broker.transitions.state == "not_started"):
|
||||||
while not bumper.mqtt_server.broker.transitions.state == "stopped":
|
# close session writers - this was required so bots would reconnect properly after restarting
|
||||||
await asyncio.sleep(0.1)
|
for sess in list(bumper.mqtt_server.broker._sessions):
|
||||||
|
sessobj = bumper.mqtt_server.broker._sessions[sess][1]
|
||||||
|
if sessobj.session.transitions.state == "connected":
|
||||||
|
await sessobj.writer.close()
|
||||||
|
|
||||||
|
aloop = asyncio.get_event_loop()
|
||||||
|
aloop.call_later(
|
||||||
|
0.1, lambda: asyncio.create_task(bumper.mqtt_server.broker.shutdown())
|
||||||
|
) # In .1 seconds shutdown broker
|
||||||
|
|
||||||
|
aloop = asyncio.get_event_loop()
|
||||||
|
aloop.call_later(
|
||||||
|
1.5, lambda: asyncio.create_task(bumper.mqtt_server.broker_coro())
|
||||||
|
) # In 1.5 seconds start broker
|
||||||
|
|
||||||
await bumper.mqtt_server.broker_coro()
|
|
||||||
while not bumper.mqtt_server.broker.transitions.state == "started":
|
|
||||||
await asyncio.sleep(0.1)
|
|
||||||
|
|
||||||
async def restart_XMPP(self):
|
async def restart_XMPP(self):
|
||||||
bumper.xmpp_server.disconnect()
|
bumper.xmpp_server.disconnect()
|
||||||
|
|
@ -358,8 +366,8 @@ class ConfServer:
|
||||||
await self.restart_MQTT()
|
await self.restart_MQTT()
|
||||||
aloop = asyncio.get_event_loop()
|
aloop = asyncio.get_event_loop()
|
||||||
aloop.call_later(
|
aloop.call_later(
|
||||||
2, lambda: asyncio.create_task(self.restart_Helper())
|
5, lambda: asyncio.create_task(self.restart_Helper())
|
||||||
) # In 2 seconds restart Helperbot
|
) # In 5 seconds restart Helperbot
|
||||||
return web.json_response({"status": "complete"})
|
return web.json_response({"status": "complete"})
|
||||||
elif service == "XMPPServer":
|
elif service == "XMPPServer":
|
||||||
await self.restart_XMPP()
|
await self.restart_XMPP()
|
||||||
|
|
@ -369,6 +377,7 @@ class ConfServer:
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
confserverlog.exception("{}".format(e))
|
confserverlog.exception("{}".format(e))
|
||||||
|
pass
|
||||||
|
|
||||||
async def handle_login(self, request):
|
async def handle_login(self, request):
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class MQTTHelperBot:
|
||||||
try:
|
try:
|
||||||
if self.Client is None:
|
if self.Client is None:
|
||||||
self.Client = MQTTClient(
|
self.Client = MQTTClient(
|
||||||
client_id=self.client_id, config={"check_hostname": False}
|
client_id=self.client_id, config={"check_hostname": False, "reconnect_retries": 20}
|
||||||
)
|
)
|
||||||
|
|
||||||
await self.Client.connect(
|
await self.Client.connect(
|
||||||
|
|
@ -207,7 +207,7 @@ class MQTTHelperBot:
|
||||||
|
|
||||||
|
|
||||||
class MQTTServer:
|
class MQTTServer:
|
||||||
default_config = {}
|
default_config = None
|
||||||
broker = None
|
broker = None
|
||||||
|
|
||||||
async def broker_coro(self):
|
async def broker_coro(self):
|
||||||
|
|
@ -215,19 +215,19 @@ class MQTTServer:
|
||||||
mqttserverlog.info(
|
mqttserverlog.info(
|
||||||
"Starting MQTT Server at {}:{}".format(self.address[0], self.address[1])
|
"Starting MQTT Server at {}:{}".format(self.address[0], self.address[1])
|
||||||
)
|
)
|
||||||
self.broker = hbmqtt.broker.Broker(config=self.default_config)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.broker.start()
|
await self.broker.start()
|
||||||
|
|
||||||
except hbmqtt.broker.BrokerException as e:
|
except hbmqtt.broker.BrokerException as e:
|
||||||
mqttserverlog.exception(e)
|
mqttserverlog.exception(e)
|
||||||
asyncio.create_task(bumper.shutdown())
|
#asyncio.create_task(bumper.shutdown())
|
||||||
pass
|
pass
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
mqttserverlog.exception("{}".format(e))
|
mqttserverlog.exception("{}".format(e))
|
||||||
asyncio.create_task(bumper.shutdown())
|
#asyncio.create_task(bumper.shutdown())
|
||||||
|
pass
|
||||||
|
|
||||||
def __init__(self, address):
|
def __init__(self, address):
|
||||||
try:
|
try:
|
||||||
|
|
@ -252,7 +252,7 @@ class MQTTServer:
|
||||||
"keyfile": bumper.server_key,
|
"keyfile": bumper.server_key,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"sys_interval": 10,
|
"sys_interval": 0,
|
||||||
"auth": {
|
"auth": {
|
||||||
"allow-anonymous": False, # Set to True to allow anonymous authentication
|
"allow-anonymous": False, # Set to True to allow anonymous authentication
|
||||||
"password-file": os.path.join(
|
"password-file": os.path.join(
|
||||||
|
|
@ -263,6 +263,8 @@ class MQTTServer:
|
||||||
"topic-check": {"enabled": False},
|
"topic-check": {"enabled": False},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.broker = hbmqtt.broker.Broker(config=self.default_config)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
mqttserverlog.exception("{}".format(e))
|
mqttserverlog.exception("{}".format(e))
|
||||||
|
|
||||||
|
|
@ -401,6 +403,11 @@ class BumperMQTTServer_Plugin:
|
||||||
bumper.client_set_mqtt(client["resource"], True)
|
bumper.client_set_mqtt(client["resource"], True)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
#async def on_broker_message_received(self, client_id, message):
|
||||||
|
#print(message)
|
||||||
|
# Look at replacing helperbot with code here
|
||||||
|
|
||||||
|
|
||||||
async def on_broker_client_disconnected(self, client_id):
|
async def on_broker_client_disconnected(self, client_id):
|
||||||
|
|
||||||
didsplit = str(client_id).split("@")
|
didsplit = str(client_id).split("@")
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,48 @@
|
||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
|
||||||
<title>Bumper</title>
|
<title>Bumper</title>
|
||||||
|
<meta http-equiv="refresh" content="5" />
|
||||||
|
<script>
|
||||||
|
function restartHelperbot() {
|
||||||
|
console.log("restart helperbot");
|
||||||
|
fetch('restart_Helperbot')
|
||||||
|
.then((response) => {
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then((myJson) => {
|
||||||
|
alert("Restarting Helperbot: " + myJson["status"])
|
||||||
|
console.log("restart helperbot - " + myJson["status"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function restartMQTTServer() {
|
||||||
|
console.log("restart mqtt server");
|
||||||
|
fetch('restart_MQTTServer')
|
||||||
|
.then((response) => {
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then((myJson) => {
|
||||||
|
alert("Restarting MQTT Server: " + myJson["status"])
|
||||||
|
console.log("restart mqtt server - " + myJson["status"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function restartXMPPServer() {
|
||||||
|
console.log("restart xmpp server");
|
||||||
|
fetch('restart_XMPPServer')
|
||||||
|
.then((response) => {
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then((myJson) => {
|
||||||
|
alert("Restarting XMPP Server: " + myJson["status"])
|
||||||
|
console.log("restart xmpp server - " + myJson["status"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<ul id="navigation">
|
<ul id="navigation">
|
||||||
|
|
@ -11,21 +53,26 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div class="container-fluid col-8">
|
<div class="col-8">
|
||||||
<h1>Bumper</h1>
|
<h1>Bumper</h1>
|
||||||
|
|
||||||
<!-- Section Stats -->
|
<!-- Section Stats -->
|
||||||
<div class="card bg-light border-dark">
|
<div class="card bg-light border-dark">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h2 class="card-title">Bumper Server Status</h2>
|
<h2 class="card-title">Server Status</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
|
||||||
<h3>MQTT Server</h3>
|
<div class="card border border-dark">
|
||||||
|
<div class="card card-header">
|
||||||
|
<h3 class="card-title">MQTT Server</h3>
|
||||||
|
<div>Action: <button type="button" class="btn btn-outline-danger btn-sm" onclick="restartMQTTServer();">Restart Service</button></div>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
Status: {% if mqtt_server[0].state == "started" %} <span class="badge badge-success">{{ mqtt_server[0].state }}</span> {% else %} <span class="badge badge-danger">{{ mqtt_server[0].state }}</span> {% endif %}
|
Status: {% if mqtt_server[0].state == "started" %} <span class="badge badge-success">{{ mqtt_server[0].state }}</span> {% else %} <span class="badge badge-danger">{{ mqtt_server[0].state }}</span> {% endif %}
|
||||||
Sessions: {{ mqtt_server[1].sessions[0].count }}
|
Sessions: {{ mqtt_server[1].sessions[0].count }}
|
||||||
|
|
||||||
<table class="table table-striped table-bordered">
|
<table class="table table-striped table-bordered table-responsive-lg">
|
||||||
<thead class="thead-dark">
|
<thead class="thead-dark">
|
||||||
<TH>username</TH><TH>clientid</TH><TH>state</TH>
|
<TH>username</TH><TH>clientid</TH><TH>state</TH>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
@ -38,11 +85,21 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h3>XMPP Server</h3>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</br>
|
||||||
|
|
||||||
|
<div class="card border border-dark">
|
||||||
|
<div class="card card-header">
|
||||||
|
<h3 class="card-title">XMPP Server</h3>
|
||||||
|
<div>Action: <button type="button" class="btn btn-outline-danger btn-sm" onclick="restartXMPPServer();">Restart Service</button></div>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
Status: {% if xmpp_server.server._serving == True %} <span class="badge badge-success">running</span> {% else %} <span class="badge badge-danger">not running</span> {% endif %}
|
Status: {% if xmpp_server.server._serving == True %} <span class="badge badge-success">running</span> {% else %} <span class="badge badge-danger">not running</span> {% endif %}
|
||||||
Clients: {{ xmpp_server.clients | length }}
|
Clients: {{ xmpp_server.clients | length }}
|
||||||
|
|
||||||
<table class="table table-striped table-bordered">
|
<table class="table table-striped table-bordered table-responsive-lg">
|
||||||
<thead class="thead-dark">
|
<thead class="thead-dark">
|
||||||
<TH>uid</TH><TH>jid</TH><TH>state</TH>
|
<TH>uid</TH><TH>jid</TH><TH>state</TH>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
@ -55,23 +112,36 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h3>Helperbot</h3>
|
</br>
|
||||||
Status: {% if helperbot[0].state == "connected" %} <span class="badge badge-success">{{ helperbot[0].state }}</span> {% else %} <span class="badge badge-danger">{{ helperbot[0].state }}</span> {% endif %}
|
|
||||||
|
<div class="card border border-dark">
|
||||||
|
<div class="card card-header">
|
||||||
|
<h3 class="card-title">Helperbot</h3>
|
||||||
|
<div>Action: <button type="button" class="btn btn-outline-danger btn-sm" onclick="restartHelperbot();">Restart Service</button></div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="card-body">
|
||||||
|
Status: {% if helperbot[0].state == "connected" %} <span class="badge badge-success">{{ helperbot[0].state }}</span> {% else %} <span class="badge badge-danger">{{ helperbot[0].state }}</span> {% endif %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</br>
|
</br>
|
||||||
|
|
||||||
<!-- Section Bots -->
|
<!-- Section Bots -->
|
||||||
<div class="card bg-light border-dark">
|
<div class="card border-dark">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h2 class="card-title">Bots</h2>
|
<h2 class="card-title">Bots</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<table class="table table-striped table-bordered">
|
<table class="table table-striped table-bordered table-responsive-lg">
|
||||||
<thead class="thead-dark">
|
<thead class="thead-dark">
|
||||||
<TH>SN</TH><TH>Nickname</TH><TH>Class</TH><TH>DID</TH><TH>Resource</TH><TH>Company</TH><TH>MQTT Connected</TH><TH>XMPP Connected</TH>
|
<TH>SN</TH><TH>Nickname</TH><TH>Class</TH><TH>DID</TH><TH>Resource</TH><TH>Company</TH><TH>MQTT Connected</TH><TH>XMPP Connected</TH>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
@ -95,12 +165,12 @@
|
||||||
</br>
|
</br>
|
||||||
|
|
||||||
<!-- Section Clients -->
|
<!-- Section Clients -->
|
||||||
<div class="card bg-light border-dark">
|
<div class="card border-dark">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h2 class="card-title">Clients</h2>
|
<h2 class="card-title">Clients</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<table class="table table-striped table-bordered">
|
<table class="table table-striped table-bordered table-responsive-lg">
|
||||||
<thead class="thead-dark">
|
<thead class="thead-dark">
|
||||||
<TH>User ID</TH><TH>Realm</TH><TH>Resource</TH><TH>MQTT Connected</TH><TH>XMPP Connected</TH>
|
<TH>User ID</TH><TH>Realm</TH><TH>Resource</TH><TH>MQTT Connected</TH><TH>XMPP Connected</TH>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue