mirror of
https://github.com/bunkerity/bunkerized-nginx
synced 2023-12-13 21:30:18 +01:00
UI - fix instances bugs
This commit is contained in:
parent
ba197dfa43
commit
4947796c99
2 changed files with 21 additions and 6 deletions
|
@ -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 !"
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue