UI - fix instances bugs

This commit is contained in:
bunkerity 2021-07-09 11:26:23 +02:00
parent ba197dfa43
commit 4947796c99
No known key found for this signature in database
GPG Key ID: 3D80806F12602A7C
2 changed files with 21 additions and 6 deletions

View File

@ -299,4 +299,6 @@ echo "[*] Download proxies list"
do_and_check_cmd /opt/bunkerized-nginx/scripts/geoip.sh
# We're done
echo "[*] Remove temp files"
do_and_check_cmd rm -rf /tmp/bunkerized-nginx
echo "[*] bunkerized-nginx successfully installed !"

View File

@ -1,4 +1,4 @@
import docker, os, requests
import docker, os, requests, subprocess
class Instances :
@ -16,6 +16,7 @@ class Instances :
instance["type"] = type
instance["status"] = status
instance["data"] = data
return instance
def __api_request(self, instance, order) :
result = True
@ -34,6 +35,13 @@ class Instances :
except :
result = False
def __instance_from_id(self, id) :
instances = self.get_instances()
for instance in instances :
if instance["id"] == id :
return instance
raise Exception("Can't find instance with id " + id)
def get_instances(self) :
instances = []
@ -87,17 +95,20 @@ class Instances :
return all_reload
def reload_instance(self, instance) :
def reload_instance(self, id) :
instance = self.__instance_from_id(id)
result = True
if instance["type"] == "local" :
instance["data"].kill(signal="SIGHUP")
proc = subprocess.run(["/usr/sbin/nginx", "-s", "reload"], capture_output=True)
result = proc.returncode == 0
elif instance["type"] == "container" or instance["type"] == "service" :
result = self.__api_request(instance, "/reload")
if result :
return "Instance " + instance["name"] + " has been reloaded."
return "Can't reload " + instance["name"]
def start_instance(self, instance) :
def start_instance(self, id) :
instance = self.__instance_from_id(id)
result = True
if instance["type"] == "local" :
proc = subprocess.run(["/usr/sbin/nginx", "-g", "daemon on;"], capture_output=True)
@ -108,7 +119,8 @@ class Instances :
return "Instance " + instance["name"] + " has been started."
return "Can't start " + instance["name"]
def stop_instance(self, instance) :
def stop_instance(self, id) :
instance = self.__instance_from_id(id)
result = True
if instance["type"] == "local" :
proc = subprocess.run(["/usr/sbin/nginx", "-s", "quit"], capture_output=True)
@ -119,7 +131,8 @@ class Instances :
return "Instance " + instance["name"] + " has been stopped."
return "Can't stop " + instance["name"]
def restart_instance(self, instance) :
def restart_instance(self, id) :
instance = self.__instance_from_id(id)
result = True
if instance["type"] == "local" :
proc = subprocess.run(["/usr/sbin/nginx", "-s", "quit"], capture_output=True)